Class: IniParse::SectionCollection

Inherits:
Object
  • Object
show all
Includes:
LineCollection
Defined in:
lib/iniparse/line_collection.rb

Overview

A implementation of LineCollection used for storing (mostly) Option instances contained within a Section.

Since it is assumed that an INI document will only represent a section once, if SectionCollection encounters a Section key already held in the collection, the existing section is merged with the new one (see IniParse::Lines::Section#merge!).

Instance Method Summary collapse

Methods included from LineCollection

#[], #[]=, #delete, #each, #has_key?, #initialize, #keys, #to_a, #to_hash

Instance Method Details

#<<(line) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/iniparse/line_collection.rb', line 115

def <<(line)
  if line.kind_of?(IniParse::Lines::Option) || (has_key?('__anonymous__') && (line.blank? || line.kind_of?(IniParse::Lines::Comment)))
    option = line
    line   = IniParse::Lines::AnonymousSection.new

    line.lines << option if option
  end

  if line.blank? || (! has_key?(line.key))
    super # Adding a new section, comment or blank line.
  else
    self[line.key].merge!(line)
  end

  self
end