In Files

Files

Ini

 encoding: us-ascii

 INI File Parser

 Version: 0.1
 License: Public Domain
 Author: Dice <scl@dc.littlestar.jp>

Constants

VERSION
(Not documented)
VERSION_NUMBER
(Not documented)

Public Class Methods

parse(text, filename = self.to_s) click to toggle source

(Not documented)

# File ini.rb, line 15
        def self.parse(text, filename = self.to_s)
                re = {}
                current_section = nil
                
                text.each_with_index do |line, index|
                        case line.chomp
                        when /^\;/, /^\s*$/
                                # skip (primary)
                        when /^\[(.+)\]/
                                # section start
                                current_section = $1
                                if re[current_section] then
                                        self.warn(filename, index+1, "section '#{$1}' overlap")
                                else
                                        re[current_section] = {}
                                end
                                
                        when /^(.+?)\s*=\s*(.*)$/
                                # key and value
                                if current_section then
                                        if re[current_section][$1] then
                                                self.warn(filename, index+1, "key '#{$1}' overlap")
                                        end
                                        
                                        re[current_section][$1] = $2
                                else
                                        self.warn(filename, index+1, "'#{$1}' is not in section")
                                end
                        else
                                self.warn(filename, index+1, "warning: unknown statement")
                        end
                end
                
                re
        end
parse_file(path) click to toggle source

(Not documented)

# File ini.rb, line 51
        def self.parse_file(path)
                self.parse(File.read(path), path.to_s)
        end
warn(filename, lineno, msg) click to toggle source

(Not documented)

# File ini.rb, line 55
        def self.warn(filename, lineno, msg)
                if $VERBOSE or $DEBUG then
                        $stderr.puts "#{filename}:#{lineno}: warning: #{msg}"
                end
        end

Disabled; run with $DEBUG to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.