Class: JsonStreamTrigger
- Inherits:
-
Object
- Object
- JsonStreamTrigger
- Defined in:
- lib/json_stream_trigger.rb
Constant Summary collapse
- DEBUG =
false
Instance Attribute Summary collapse
-
#full_buffer ⇒ Object
readonly
Returns the value of attribute full_buffer.
-
#key_path ⇒ Object
readonly
Returns the value of attribute key_path.
-
#triggers ⇒ Object
readonly
Returns the value of attribute triggers.
Instance Method Summary collapse
- #<<(bytes) ⇒ Object
-
#initialize ⇒ JsonStreamTrigger
constructor
A new instance of JsonStreamTrigger.
- #on(pattern, &block) ⇒ Object
- #path_matches?(pattern) ⇒ Boolean
Constructor Details
#initialize ⇒ JsonStreamTrigger
Returns a new instance of JsonStreamTrigger.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/json_stream_trigger.rb', line 9 def initialize() @parser = JSON::Stream::Parser.new @parser.start_object &method(:start_object) @parser.end_object &method(:end_object) @parser.start_array &method(:start_array) @parser.end_array &method(:end_array) @parser.key &method(:key) @parser.value &method(:value) @last_call = nil @key_path = '' @triggers = {} @active_buffers = {} @full_buffer = '' end |
Instance Attribute Details
#full_buffer ⇒ Object (readonly)
Returns the value of attribute full_buffer.
6 7 8 |
# File 'lib/json_stream_trigger.rb', line 6 def full_buffer @full_buffer end |
#key_path ⇒ Object (readonly)
Returns the value of attribute key_path.
6 7 8 |
# File 'lib/json_stream_trigger.rb', line 6 def key_path @key_path end |
#triggers ⇒ Object (readonly)
Returns the value of attribute triggers.
6 7 8 |
# File 'lib/json_stream_trigger.rb', line 6 def triggers @triggers end |
Instance Method Details
#<<(bytes) ⇒ Object
30 31 32 33 34 |
# File 'lib/json_stream_trigger.rb', line 30 def <<(bytes) debug "bytes: #{bytes.inspect}" @parser << bytes @full_buffer << bytes if DEBUG end |
#on(pattern, &block) ⇒ Object
26 27 28 |
# File 'lib/json_stream_trigger.rb', line 26 def on(pattern, &block) @triggers[pattern] = block end |