Class: Bigrig::OutputParser
- Inherits:
-
Object
- Object
- Bigrig::OutputParser
- Defined in:
- lib/bigrig/output_parser.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#as_array(input) ⇒ Object
WTF jruby?!.
-
#initialize ⇒ OutputParser
constructor
A new instance of OutputParser.
- #parse(input) ⇒ Object
Constructor Details
#initialize ⇒ OutputParser
Returns a new instance of OutputParser.
8 9 10 11 |
# File 'lib/bigrig/output_parser.rb', line 8 def initialize @last_line = '' @buffer = '' end |
Class Method Details
.parser_proc ⇒ Object
3 4 5 6 |
# File 'lib/bigrig/output_parser.rb', line 3 def self.parser_proc parser = OutputParser.new proc { |chunk| print parser.parse chunk } end |
Instance Method Details
#as_array(input) ⇒ Object
WTF jruby?!
14 15 16 17 18 19 20 |
# File 'lib/bigrig/output_parser.rb', line 14 def as_array(input) if input.is_a? Enumerator input.each_with_object([]) { |ch, x| x << ch } else input end end |
#parse(input) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/bigrig/output_parser.rb', line 22 def parse(input) output = documents(input).map do |json| if json['errorDetail'] "#{json['errorDetail']['message'].red}\n" elsif json['stream'] || json['id'].nil? json['stream'] || "#{json['status']}\n" else parse_progress json end end output.join end |