module IniParse::LineCollection

def <<(line)


collection, the old item will be replaced.
Note that if you pass a line with a key already represented in the

Appends a line to the collection.
def <<(line)
  line.blank? ? (@lines << line) : (self[line.key] = line) ; self
end

def [](key)

Retrive a value identified by +key+.
def [](key)
  has_key?(key) ? @lines[ @indicies[key] ] : nil
end

def []=(key, value)


with the new one, with the new value taking the position of the old.
If a value with the given key already exists, the value will be replaced

Set a +value+ identified by +key+.
def []=(key, value)
  key = key.to_s
  if has_key?(key)
    @lines[ @indicies[key] ] = value
  else
    @lines << value
    @indicies[key] = @lines.length - 1
  end
end

def delete(key)

Removes the value identified by +key+.
def delete(key)
  key = key.key if key.respond_to?(:key)
  unless (idx = @indicies[key]).nil?
    @indicies.delete(key)
    @indicies.each { |k,v| @indicies[k] = v -= 1 if v > idx }
    @lines.delete_at(idx)
  end
end

def each(include_blank = false)


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

By default #each does not yield blank and comment lines.

Enumerates through the collection.
def each(include_blank = false)
  @lines.each do |line|
    if include_blank || ! (line.is_a?(Array) ? line.empty? : line.blank?)
      yield(line)
    end
  end
end

def has_key?(*args)

Returns whether +key+ is in the collection.
def has_key?(*args)
  @indicies.has_key?(*args)
end

def initialize

def initialize
  @lines    = []
  @indicies = {}
end

def keys

collection.
Return an array containing the keys for the lines added to this
def keys
  map { |line| line.key }
end

def to_a

Returns this collection as an array. Includes blank and comment lines.
def to_a
  @lines.dup
end

def to_hash

lines.
Returns this collection as a hash. Does not contain blank and comment
def to_hash
  Hash[ *(map { |line| [line.key, line] }).flatten ]
end