Sha256: 5dcd144d967b53c72c0033507e0b625fec73da57d90dea4622dc687cd18a2dd4
Contents?: true
Size: 946 Bytes
Versions: 19
Compression:
Stored size: 946 Bytes
Contents
module GnipApi module Apis module PowerTrack class Buffer attr_reader :terminator, :data def initialize options={} @terminator = options.delete(:terminator) || "\r\n" @data = "" end def size @data.size end def insert! chunk @data << chunk end def read! objects = @data.split(terminator)[0..-2] unless objects.empty? # Get the number of chars to read from buffer, counting # the size of each splited chunk plus the number of chunks by # terminator size, since it's still present in the buffer size = objects.map(&:size).reduce(:+) + objects.size * terminator.size consume!(size) end return objects end def consume! chars @data[0..chars-1] = '' end end end end end
Version data entries
19 entries across 19 versions & 1 rubygems