Class: OptionsDB

Inherits:
Object
  • Object
show all
Defined in:
lib/cless/optionsdb.rb

Instance Method Summary collapse

Constructor Details

#initialize(*files) ⇒ OptionsDB

Returns a new instance of OptionsDB.



2
3
4
5
6
# File 'lib/cless/optionsdb.rb', line 2

def initialize(*files)
  @names = {}
  @regexps = {}
  files.each { |f| parse_file(f) }
end

Instance Method Details

#[](name) ⇒ Object



28
# File 'lib/cless/optionsdb.rb', line 28

def [](name); name.nil? ? nil : @names[name]; end

#match(fname) ⇒ Object



21
22
23
24
25
26
# File 'lib/cless/optionsdb.rb', line 21

def match(fname)
  @regexps.each do |regexp, v|
    return v if fname =~ regexp
  end
  nil
end

#parse_file(name) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/cless/optionsdb.rb', line 8

def parse_file(name)
  File.open(File.expand_path(name)) do |fd|
    fd.each_line do |l|
      a = l.split_with_quotes
      n = a.shift
      r = a.shift
      @names[n] = a
      @regexps[Regexp.new(r)] = a
    end
  end
  true
end