Class: IniParse::OptionCollection
- Inherits:
-
Object
- Object
- IniParse::OptionCollection
- Includes:
- LineCollection
- Defined in:
- lib/iniparse/line_collection.rb
Overview
A implementation of LineCollection used for storing (mostly) Option instances contained within a Section.
Whenever OptionCollection encounters an Option key already held in the collection, it treats it as a duplicate. This means that instead of overwriting the existing value, the value is changed to an array containing the previous and the new Option instances.
Instance Method Summary collapse
-
#<<(line) ⇒ Object
Appends a line to the collection.
-
#keys ⇒ Object
Return an array containing the keys for the lines added to this collection.
Methods included from LineCollection
#[], #[]=, #delete, #each, #has_key?, #initialize, #to_a, #to_hash
Instance Method Details
#<<(line) ⇒ Object
Appends a line to the collection.
If you push an Option with a key already represented in the collection, the previous Option will not be overwritten, but treated as a duplicate.
Parameters
- line<IniParse::LineType::Line>
-
The line to be added to this section.
149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/iniparse/line_collection.rb', line 149 def <<(line) if line.kind_of?(IniParse::Lines::Section) raise IniParse::LineNotAllowed, "You can't add a Section to an OptionCollection." end if line.blank? || (! has_key?(line.key)) super # Adding a new option, comment or blank line. else self[line.key] = [self[line.key], line].flatten end self end |
#keys ⇒ Object
Return an array containing the keys for the lines added to this collection.
166 167 168 |
# File 'lib/iniparse/line_collection.rb', line 166 def keys map { |line| line.kind_of?(Array) ? line.first.key : line.key } end |