Upgrade help plugin
[dcbot.git] / config.rb
blob1a1008c0ae6f8c539c0169e271ab61f009adf83f
1 module IniReader
2   def self.read(filename)
3     File.open(filename, "r") do |f|
4       read_stream(f)
5     end
6   end
7   
8   def self.read_stream(io)
9     config = []
10     name = ""
11     section = {}
12     until (line = io.gets).nil?
13       if line =~ /^\s*#/ then
14         # do nothing
15       elsif line =~ /^\[(.*)\]\s*$/ then
16         config << [name, section]
17         name = $1
18         section = {}
19       elsif line =~ /^\s*(.*?)\s*=\s*(.*?)\s*$/ then
20         section[$1] = $2
21       end
22     end
23     config << [name, section]
24     if config.size > 0 and config[0][0] == "" and config[0][1].empty? then
25       config.delete_at 0
26     end
27     config
28   end
29 end