Sha256: 125f11cff05883e6c349aa8e1ad1247ec5b6e79761649ede03c5a5746002d2e0
Contents?: true
Size: 940 Bytes
Versions: 1
Compression:
Stored size: 940 Bytes
Contents
class IniReader def initialize( string = '') @section_hash = {} parse(StringIO.new(string)) end def self.parse(filename) reader = IniReader.new reader.send(:parse, File.open(filename, "r")) return reader end #returns the hash for a section of the inifile def []( section_name ) return @section_hash[section_name] end private def parse(io) current_section = nil io.each do |line| line = line.strip if line[0] == ';' next elsif ( matchdata = line.match(/^\[(.+)\]$/) ) != nil current_section = @section_hash[matchdata[1].to_sym] || {} @section_hash[matchdata[1].to_sym] = current_section elsif ( matchdata = line.match(/^([^=]*)=(.*)$/) ) current_section[matchdata[1].to_sym] = matchdata[2].to_s elsif line.strip == "" next else raise Exception("Could not parse line: #{line}") end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
inireader-0.1.1 | lib/inireader/base.rb |