public
Description: Direct Connect bot written in Ruby
Clone URL: git://github.com/kballard/dcbot.git
Search Repo:
kballard (author)
Wed Mar 12 19:47:02 -0700 2008
commit  5a498b0375a742aac109c5b3833829ce9660e0b1
tree    a68da762c027363f211d1975cb0267b12b55da3d
parent  2d19cf48643fd55d9573576e9ad8486894d7586f
dcbot / config.rb
100644 30 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
30
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