Class: Lingo::Srv

Inherits:
App
  • Object
show all
Defined in:
lib/lingo/srv.rb

Constant Summary collapse

LINGO =
Call.new(ARGV).call
SRC_SEP =
c == true ? Attendee::VectorFilter::DEFAULT_SRC_SEPARATOR : c

Instance Method Summary collapse

Methods inherited from App

init_app, parse_options, rackup, #to_json

Instance Method Details

#doitObject



50
51
52
53
54
55
# File 'lib/lingo/srv.rb', line 50

def doit
  to_json(q = params[:q], case q
    when String then talk(q)
    when Array  then q.inject({}) { |h, k| h[k] = talk(k); h }
  end)
end

#talk(q) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/lingo/srv.rb', line 57

def talk(q)
  r = LINGO.talk(q) unless q.empty?
  return r unless r && SRC_SEP

  s = Hash.array

  r.each { |t|
    a, b = t.split(SRC_SEP, 2)
    s[b] << a
  }

  ENV['LINGO_NO_SORT'] ? s.to_a : s
end