Sha256: c6d0cdd8144d761d5c4807f1b4a6e5f9a49633164ca8fc6df68a8bd504e82eb0

Contents?: true

Size: 738 Bytes

Versions: 3

Compression:

Stored size: 738 Bytes

Contents

module Ini
  def parse_ini(input)
    hash = {}
    current_section = nil
    
    input.each_line do |line|
      line = line.sub(/\;.*$/, '').strip.chomp.strip # strip comments
      next if line.strip.empty?
      
      if line.strip =~ /\[([^\]]+)\]/
        current_section = $1.downcase
        hash[current_section] ||= {}
      else
        key, value = line.split('=')
        
        value.strip!
        value = case value
                when /0x[\da-f]/i     : value.hex
                when /^[\+\-]?\d+$/   : value.to_i
                when /^\"(.*)\"$/     : $1
                else value
                end
        hash[current_section][key.downcase] = value
      end
    end
    
    hash
  end
  
  extend self
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
elia-2.4.2.pre lib/ini.rb
elia-2.4.1 lib/ini.rb
elia-2.3.2 lib/ini.rb