class IniParse::OptionCollection

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.

Public Instance Methods

<<(line) click to toggle source

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.

Calls superclass method IniParse::LineCollection#<<
# 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() click to toggle source

Return an array containing the keys for the lines added to this collection.

# File lib/iniparse/line_collection.rb, line 166
def keys
  map { |line| line.kind_of?(Array) ? line.first.key : line.key }
end