class Lingo::Config

Public Class Methods

new(*args) click to toggle source
# File lib/lingo/config.rb, line 33
def initialize(*args)
  @cli, @opts = CLI.new, {}

  @cli.execute(*args)
  @cli.options.each { |key, val| @opts[key.to_s] = val }

  load_config('language', :lang)
  load_config('config')

  Array(self['meeting/attendees']).each { |a|
    r = a['text_reader'] || a['textreader'] or next  # DEPRECATE textreader


    f = @cli.files

    if i = r['files']
      r['files'] = i.strip == '$(files)' ? f : i.split(SEP_RE)
    elsif !f.empty?
      r['files'] = f
    end

    break
  }
end

Public Instance Methods

[](key) click to toggle source
# File lib/lingo/config.rb, line 57
def [](key)
  key_to_nodes(key).inject(@opts) { |hash, node| hash[node] }
end
[]=(key, val) click to toggle source
# File lib/lingo/config.rb, line 61
def []=(key, val)
  nodes = key_to_nodes(key); node = nodes.pop
  (self[nodes_to_key(nodes)] ||= {})[node] = val
end
quit(*args) click to toggle source
# File lib/lingo/config.rb, line 78
def quit(*args)
  @cli.send(:quit, *args)
end
stderr() click to toggle source
# File lib/lingo/config.rb, line 74
def stderr
  @cli.stderr
end
stdin() click to toggle source
# File lib/lingo/config.rb, line 66
def stdin
  @cli.stdin
end
stdout() click to toggle source
# File lib/lingo/config.rb, line 70
def stdout
  @cli.stdout
end

Private Instance Methods

key_to_nodes(key) click to toggle source
# File lib/lingo/config.rb, line 84
def key_to_nodes(key)
  key.downcase.split('/')
end
load_config(key, type = key.to_sym) click to toggle source
# File lib/lingo/config.rb, line 92
def load_config(key, type = key.to_sym)
  file = Lingo.find(type, @opts[key], &method(:quit))
  @opts.update(File.open(file, encoding: ENC, &YAML.method(:load)))
end
nodes_to_key(nodes) click to toggle source
# File lib/lingo/config.rb, line 88
def nodes_to_key(nodes)
  nodes.join('/')
end