class IniParse::Lines::Section


of a string of characters wrapped in square brackets.
Represents a section header in an INI document. Section headers consist

def self.parse(line, opts)

def self.parse(line, opts)
  if m = @regex.match(line)
    [:section, m[1], opts]
  end
end

def [](key)


the value of each option.
matches a set of duplicate options, an array will be returned containing
Returns nil if there is no corresponding option. If the key provided

Returns the value of an option identified by +key+.
def [](key)
  key = key.to_s
  if @lines.has_key?(key)
    if (match = @lines[key]).kind_of?(Array)
      match.map { |line| line.value }
    else
      match.value
    end
  end
end

def []=(key, value)


new option to be considered a duplicate, use +add_option+ instead.
If you do not wish to overwrite duplicates, but wish instead for your

# => 'new value'
section['an_option]
section['an_option'] = 'new value'
# => ['duplicate one', 'duplicate two', ...]
section['an_option']

overwrite duplicate options with your new value.
Note that +[]=+ has no knowledge of duplicate options and will happily

Adds a new option to this section, or updates an existing one.
def []=(key, value)
  @lines[key.to_s] = IniParse::Lines::Option.new(key.to_s, value)
end

def delete(*args)


Returns the section.

Deletes the option identified by +key+.
def delete(*args)
  @lines.delete(*args)
  self
end

def each(*args, &blk)


include_blank:: Include blank/comment lines?
==== Parameters

lines to be yielded, pass true.
Does not yield blank and comment lines by default; if you want _all_

Enumerates through each Option in this section.
def each(*args, &blk)
  @lines.each(*args, &blk)
end

def has_option?(key)

Returns true if an option with the given +key+ exists in this section.
def has_option?(key)
  @lines.has_key?(key.to_s)
end

def initialize(key, opts = {})


opts:: Extra options for the line.
key:: The section name.
==== Parameters
def initialize(key, opts = {})
  super(opts)
  @key   = key.to_s
  @lines = IniParse::OptionCollection.new
end

def line_contents

def line_contents
  '[%s]' % key
end

def merge!(other)


other:: The section to merge into this one.
==== Parameters

duplicates.
this one contains options with the same key, they will be handled as
Merges section +other+ into this one. If the section being merged into
def merge!(other)
  other.lines.each(true) do |line|
    if line.kind_of?(Array)
      line.each { |duplicate| @lines << duplicate }
    else
      @lines << line
    end
  end
end

def option(key)


Will return an array of lines if the key matches a set of duplicates.

the matching line instance.
Like [], except instead of returning just the option value, it returns
def option(key)
  @lines[key.to_s]
end

def to_ini

document. Includes options, comments and blanks.
Returns this line as a string as it would be represented in an INI
def to_ini
  coll = lines.to_a
  if coll.any?
    super + $/ + coll.to_a.map do |line|
      if line.kind_of?(Array)
        line.map { |dup_line| dup_line.to_ini }.join($/)
      else
        line.to_ini
      end
    end.join($/)
  else
    super
  end
end