Sha256: c797e4773457e9082b669c66c376e0c703dc97bc4eb1d033c3c99eef209aa73a

Contents?: true

Size: 811 Bytes

Versions: 11

Compression:

Stored size: 811 Bytes

Contents

module Gnip
  module GnipStream
    class JsonDataBuffer 
    
      attr_accessor :split_pattern, :check_pattern
    
      def initialize(split_pattern, check_pattern)
        @split_pattern = split_pattern
        @check_pattern = check_pattern
        @buffer = ""
      end

      def process(chunk)
        @buffer.concat(chunk)
      end

      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 = @buffer + "\r\n" if @buffer.size > 0 && new_line
        end
        entries.select{ |entry| entry.size > 0 }
      end
    end
    
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
gnip-client-0.2.8 lib/gnip/gnip-stream/json_data_bufffer.rb
gnip-client-0.2.7 lib/gnip/gnip-stream/json_data_bufffer.rb
gnip-client-0.2.6 lib/gnip/gnip-stream/json_data_bufffer.rb
gnip-client-0.2.5 lib/gnip/gnip-stream/json_data_bufffer.rb
gnip-client-0.2.4 lib/gnip/gnip-stream/json_data_bufffer.rb
gnip-client-0.2.3 lib/gnip/gnip-stream/json_data_bufffer.rb
gnip-client-0.2.2 lib/gnip/gnip-stream/json_data_bufffer.rb
gnip-client-0.2.1 lib/gnip/gnip-stream/json_data_bufffer.rb
gnip-client-0.2.0 lib/gnip/gnip-stream/json_data_bufffer.rb
gnip-client-0.1.9 lib/gnip/gnip-stream/json_data_bufffer.rb
gnip-client-0.1.8 lib/gnip/gnip-stream/json_data_bufffer.rb