Class: Lingo::Call
Constant Summary collapse
- CHANNELS =
%w[stdout stderr].freeze
Constants inherited from Lingo
BASE, CURR, ENCODING, FIND_OPTIONS, HOME, PATH, SEP_RE, VERSION
Instance Attribute Summary
Attributes inherited from Lingo
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(args = []) ⇒ Call
constructor
A new instance of Call.
- #talk(input, raw = false) ⇒ Object
Methods inherited from Lingo
CLI, append_path, #attendees, basename, basepath, call, #config, ctl, #database_config, #dictionary_config, find, get_const, #invite, #lexical_hash, list, prepend_path, #reset, #start, talk, #warn
Constructor Details
#initialize(args = []) ⇒ Call
Returns a new instance of Call.
33 34 35 |
# File 'lib/lingo/call.rb', line 33 def initialize(args = []) super(args, StringIO.new, StringIO.new, StringIO.new) end |
Instance Method Details
#call ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/lingo/call.rb', line 37 def call invite if block_given? begin yield self ensure reset end else self end end |
#talk(input, raw = false) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/lingo/call.rb', line 51 def talk(input, raw = false) config.stdin.reopen( input.respond_to?(:read) ? input.read : input) start res = CHANNELS.flat_map { |key| io = config.send(key) io.rewind lines = io.readlines io.truncate(0) io.rewind lines } return res.join if raw res.each { |i| i.chomp! } block_given? ? res.map! { |i| yield i } : begin res.sort! unless ENV['LINGO_NO_SORT'] res.uniq! res end end |