public
Description: Direct Connect bot written in Ruby
Clone URL: git://github.com/kballard/dcbot.git
Search Repo:
dcbot / config.rb
100644 29 lines (28 sloc) 0.643 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
module IniReader
  def self.read(filename)
    File.open(filename, "r") do |f|
      read_stream(f)
    end
  end
  
  def self.read_stream(io)
    config = []
    name = ""
    section = {}
    until (line = io.gets).nil?
      if line =~ /^\s*#/ then
        # do nothing
      elsif line =~ /^\[(.*)\]\s*$/ then
        config << [name, section]
        name = $1
        section = {}
      elsif line =~ /^\s*(.*?)\s*=\s*(.*?)\s*$/ then
        section[$1] = $2
      end
    end
    config << [name, section]
    if config.size > 0 and config[0][0] == "" and config[0][1].empty? then
      config.delete_at 0
    end
    config
  end
end