Class: Streamer::StreamBuilder
- Inherits:
-
Object
- Object
- Streamer::StreamBuilder
- Defined in:
- lib/streamer/stream_builder.rb
Overview
StreamBuilder takes a stream configuration and builds the stream defined in it. StreamBuilder then performs the stream, given a document.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
Instance Method Summary collapse
- #filter_value ⇒ Object
-
#initialize(config) ⇒ StreamBuilder
constructor
A new instance of StreamBuilder.
- #process(payload) ⇒ Object
- #stream ⇒ Object
- #transform ⇒ Object
Constructor Details
#initialize(config) ⇒ StreamBuilder
Returns a new instance of StreamBuilder.
6 7 8 |
# File 'lib/streamer/stream_builder.rb', line 6 def initialize(config) @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/streamer/stream_builder.rb', line 5 def config @config end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
5 6 7 |
# File 'lib/streamer/stream_builder.rb', line 5 def payload @payload end |
Instance Method Details
#filter_value ⇒ Object
25 26 27 28 29 30 |
# File 'lib/streamer/stream_builder.rb', line 25 def filter_value config[:filter].inject(true) do |val, f| val &&= stream.filter(function: f[:function]).payload['filter_value'] val end end |
#process(payload) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/streamer/stream_builder.rb', line 10 def process(payload) @payload = payload stream.payload['filter_value'] = filter_value transform if stream.payload['filter_value'] stream end |
#stream ⇒ Object
32 33 34 |
# File 'lib/streamer/stream_builder.rb', line 32 def stream @stream ||= Stream.new(payload) end |
#transform ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/streamer/stream_builder.rb', line 17 def transform config[:transform].each do |tx| tx.each do |k, v| stream.send(k, v) end end end |