Class: JSE::Stream::TransformChain

Inherits:
Object
  • Object
show all
Defined in:
lib/jse/stream.rb

Instance Method Summary collapse

Constructor Details

#initialize(transforms) ⇒ TransformChain

Returns a new instance of TransformChain.



58
59
60
# File 'lib/jse/stream.rb', line 58

def initialize(transforms)
  @transforms = transforms
end

Instance Method Details

#apply(line) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/jse/stream.rb', line 62

def apply(line)
  begin
    if @transforms.empty?
      line
    else
      json = JSON.parse(line)
      @transforms.inject(json){ |j, transform| transform.apply(j) }
    end
  rescue JSON::ParserError
    $stderr.puts "Error parsing line:"
    $stderr.puts line
    true
  end
end