Class: Factorix::MODSettings::Section
- Inherits:
-
Object
- Object
- Factorix::MODSettings::Section
- Includes:
- Enumerable
- Defined in:
- lib/factorix/mod_settings.rb
Overview
Represents a section in MOD settings
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
Get the section name.
Instance Method Summary collapse
-
#[](key) ⇒ Object?
Get a setting value from this section.
-
#[]=(key, value) ⇒ Object
Set a setting value in this section.
-
#each {|key, value| ... } ⇒ Enumerator
Iterate over all settings in this section.
-
#empty? ⇒ Boolean
Check if this section has any settings.
-
#fetch(key) {|key| ... } ⇒ Object
Fetch a setting value with optional default or block.
-
#initialize(name) ⇒ Section
constructor
Initialize a new section with the given name.
-
#key?(key) ⇒ Boolean
(also: #has_key?, #include?)
Check if a key exists in this section.
-
#keys ⇒ Array<String>
Get all keys in this section.
-
#size ⇒ Integer
(also: #length)
Get the number of settings in this section.
-
#to_h ⇒ Hash<String, Object>
Convert this section to a Hash.
-
#values ⇒ Array<Object>
Get all values in this section.
Constructor Details
#initialize(name) ⇒ Section
Initialize a new section with the given name
21 22 23 24 25 26 27 28 |
# File 'lib/factorix/mod_settings.rb', line 21 def initialize(name) unless VALID_SECTIONS.include?(name) raise MODSettingsError, "Invalid MOD section name: #{name}" end @name = name @settings = {} end |
Instance Attribute Details
#name ⇒ String (readonly)
Get the section name
33 34 35 |
# File 'lib/factorix/mod_settings.rb', line 33 def name @name end |
Instance Method Details
#[](key) ⇒ Object?
Get a setting value from this section
48 |
# File 'lib/factorix/mod_settings.rb', line 48 def [](key) = @settings[key] |
#[]=(key, value) ⇒ Object
Set a setting value in this section
40 41 42 |
# File 'lib/factorix/mod_settings.rb', line 40 def []=(key, value) @settings[key] = value end |
#each {|key, value| ... } ⇒ Enumerator
Iterate over all settings in this section
56 57 58 59 60 |
# File 'lib/factorix/mod_settings.rb', line 56 def each(&) return @settings.to_enum(:each) unless block_given? @settings.each(&) end |
#empty? ⇒ Boolean
Check if this section has any settings
65 |
# File 'lib/factorix/mod_settings.rb', line 65 def empty? = @settings.empty? |
#fetch(key) {|key| ... } ⇒ Object
Fetch a setting value with optional default or block
99 |
# File 'lib/factorix/mod_settings.rb', line 99 def fetch(key, *, &) = @settings.fetch(key, *, &) |
#key?(key) ⇒ Boolean Also known as: has_key?, include?
Check if a key exists in this section
71 |
# File 'lib/factorix/mod_settings.rb', line 71 def key?(key) = @settings.key?(key) |
#keys ⇒ Array<String>
Get all keys in this section
78 |
# File 'lib/factorix/mod_settings.rb', line 78 def keys = @settings.keys |
#size ⇒ Integer Also known as: length
Get the number of settings in this section
88 |
# File 'lib/factorix/mod_settings.rb', line 88 def size = @settings.size |
#to_h ⇒ Hash<String, Object>
Convert this section to a Hash
104 |
# File 'lib/factorix/mod_settings.rb', line 104 def to_h = @settings.dup |
#values ⇒ Array<Object>
Get all values in this section
83 |
# File 'lib/factorix/mod_settings.rb', line 83 def values = @settings.values |