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 151
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
each(*args) { |item| ... } click to toggle source
Calls superclass method IniParse::LineCollection#each
# File lib/iniparse/line_collection.rb, line 166
def each(*args)
  return enum_for(:each, *args) unless block_given?

  super(*args) do |value|
    if value.is_a?(Array)
      value.each { |item| yield(item) }
    else
      yield value
    end
  end
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 180
def keys
  map(&:key).uniq
end