class Lingo::Attendee

Constants

DEFAULT_SKIP
TERMINALS

Attributes

lingo[R]
subscribers[R]

Public Class Methods

new(config, lingo) click to toggle source
# File lib/lingo/attendee.rb, line 76
def initialize(config, lingo)
  @lingo, @config, @subscribers = lingo, config, []

  # Make sure config exists
  lingo.dictionary_config

  @dic, @gra, @valid_keys = nil, nil, %w[name in out]

  init

  unless (invalid_keys = config.keys - @valid_keys).empty?
    warn(
      "CONFIGURATION NOTICE: #{self.class.name.sub(/\ALingo::/, '')}" <<
      " options invalid or obsolete: #{invalid_keys.sort.join(', ')}" <<
      " (in #{lingo.config.config_file})"
    )
  end
end

Public Instance Methods

command(*args) click to toggle source
# File lib/lingo/attendee.rb, line 101
def command(*args)
  subscribers.each { |sub|
    sub.command(*args) unless sub.control(*args) == :skip_command
  }
end
forward(*args) click to toggle source
# File lib/lingo/attendee.rb, line 97
def forward(*args)
  subscribers.each { |sub| sub.process(*args) }
end

Private Instance Methods

dictionary(src, mod) click to toggle source
# File lib/lingo/attendee.rb, line 154
def dictionary(src, mod)
  Language::Dictionary.new({ 'source' => src, 'mode' => mod }, lingo)
end
find_word(f, d = @dic, g = @gra) { |w| ... } click to toggle source
# File lib/lingo/attendee.rb, line 109
def find_word(f, d = @dic, g = @gra)
  w = d.find_word(f)
  g && (block_given? ? !yield(w) : w.unknown?) ? g.find_compound(f) : w
end
flush(buffer) click to toggle source
# File lib/lingo/attendee.rb, line 114
def flush(buffer)
  buffer.each { |i| forward(i) }.clear
end
get_ary(key, default = nil, method = nil) click to toggle source
# File lib/lingo/attendee.rb, line 136
def get_ary(key, default = nil, method = nil)
  ary = get_key(key, default).split(SEP_RE)
  ary.map!(&method) if method
  ary
end
get_enc(key = 'encoding', default = ENCODING) click to toggle source
# File lib/lingo/attendee.rb, line 148
def get_enc(key = 'encoding', default = ENCODING)
  Encoding.find(get_key(key, default))
rescue ArgumentError => err
  raise ConfigLoadError.new(err)
end
get_flo(*args) click to toggle source
# File lib/lingo/attendee.rb, line 132
def get_flo(*args)
  ((val = get_key(*args)) && val.respond_to?(:to_f)) ? val.to_f : val
end
get_int(*args) click to toggle source
# File lib/lingo/attendee.rb, line 128
def get_int(*args)
  Integer(get_key(*args))
end
get_key(key, default = nodefault = true) click to toggle source
# File lib/lingo/attendee.rb, line 122
def get_key(key, default = nodefault = true)
  @valid_keys << key
  raise MissingConfigError.new(key) if nodefault && !has_key?(key)
  @config.fetch(key, default)
end
get_re(key, default = nil, standard = nil) click to toggle source
# File lib/lingo/attendee.rb, line 142
def get_re(key, default = nil, standard = nil)
  if value = get_key(key, default)
    value == true ? standard : Regexp.new(value)
  end
end
grammar(src, mod) click to toggle source
# File lib/lingo/attendee.rb, line 158
def grammar(src, mod)
  Language::Grammar.new({ 'source' => src, 'mode' => mod }, lingo)
end
has_key?(key) click to toggle source
# File lib/lingo/attendee.rb, line 118
def has_key?(key)
  @config.key?(key)
end
require_lib(lib) click to toggle source
# File lib/lingo/attendee.rb, line 174
def require_lib(lib)
  require lib
rescue LoadError => err
  raise LibraryLoadError.new(self.class, lib, err)
end
set_dic() click to toggle source
# File lib/lingo/attendee.rb, line 162
def set_dic
  @dic = dictionary(get_ary('source'), get_key('mode', 'all'))
end
set_gra() click to toggle source
# File lib/lingo/attendee.rb, line 166
def set_gra
  @gra = grammar(get_ary('source'), get_key('mode', 'all'))
end
warn(*msg) click to toggle source
# File lib/lingo/attendee.rb, line 170
def warn(*msg)
  lingo.warn(*msg)
end