Class: Console::ConfigFile

Inherits:
HashWithIndifferentAccess
  • Object
show all
Defined in:
lib/console/config_file.rb

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ ConfigFile

Returns a new instance of ConfigFile.



3
4
5
6
7
8
9
10
11
# File 'lib/console/config_file.rb', line 3

def initialize(file)
  IO.read(File.expand_path(file)).lines.
    map{ |s| s.gsub(/((^|[^\\])(\\\\)*)#.*/,'\1') }. # eliminate unescaped comments
    each do |s|
      if pair = /^\s*(.*?[^\\]+?(?:\\\\)*)=(.*)$/.match(s)
        self[pair[1].strip.gsub(/\\(.)/,'\1')] = pair[2].strip.gsub(/\\(.)/,'\1')
      end
    end
end