Class: Gnip::GnipStream::JsonDataBuffer
- Inherits:
-
Object
- Object
- Gnip::GnipStream::JsonDataBuffer
- Defined in:
- lib/gnip/gnip-stream/json_data_bufffer.rb
Instance Attribute Summary collapse
-
#check_pattern ⇒ Object
Returns the value of attribute check_pattern.
-
#split_pattern ⇒ Object
Returns the value of attribute split_pattern.
Instance Method Summary collapse
- #complete_entries ⇒ Object
-
#initialize(split_pattern, check_pattern) ⇒ JsonDataBuffer
constructor
A new instance of JsonDataBuffer.
- #process(chunk) ⇒ Object
Constructor Details
#initialize(split_pattern, check_pattern) ⇒ JsonDataBuffer
Returns a new instance of JsonDataBuffer.
6 7 8 9 10 |
# File 'lib/gnip/gnip-stream/json_data_bufffer.rb', line 6 def initialize(split_pattern, check_pattern) @split_pattern = split_pattern @check_pattern = check_pattern @buffer = '' end |
Instance Attribute Details
#check_pattern ⇒ Object
Returns the value of attribute check_pattern.
4 5 6 |
# File 'lib/gnip/gnip-stream/json_data_bufffer.rb', line 4 def check_pattern @check_pattern end |
#split_pattern ⇒ Object
Returns the value of attribute split_pattern.
4 5 6 |
# File 'lib/gnip/gnip-stream/json_data_bufffer.rb', line 4 def split_pattern @split_pattern end |
Instance Method Details
#complete_entries ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/gnip/gnip-stream/json_data_bufffer.rb', line 16 def complete_entries entries = [] while @buffer =~ check_pattern new_line = @buffer[@buffer.size - 2..@buffer.size - 1] == "\r\n" activities = @buffer.split(split_pattern) entries << activities.shift @buffer = activities.join(split_pattern) @buffer += "\r\n" if !@buffer.empty? && new_line end entries.reject(&:empty?) end |
#process(chunk) ⇒ Object
12 13 14 |
# File 'lib/gnip/gnip-stream/json_data_bufffer.rb', line 12 def process(chunk) @buffer.concat(chunk) end |