Class: GnipApi::Apis::PowerTrack::Buffer
- Inherits:
-
Object
- Object
- GnipApi::Apis::PowerTrack::Buffer
- Defined in:
- lib/gnip_api/apis/power_track/buffer.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#terminator ⇒ Object
readonly
Returns the value of attribute terminator.
Instance Method Summary collapse
- #consume!(chars) ⇒ Object
-
#initialize(options = {}) ⇒ Buffer
constructor
A new instance of Buffer.
- #insert!(chunk) ⇒ Object
- #read! ⇒ Object
- #size ⇒ Object
Constructor Details
permalink #initialize(options = {}) ⇒ Buffer
Returns a new instance of Buffer.
7 8 9 10 |
# File 'lib/gnip_api/apis/power_track/buffer.rb', line 7 def initialize ={} @terminator = .delete(:terminator) || "\r\n" @data = "" end |
Instance Attribute Details
permalink #data ⇒ Object (readonly)
Returns the value of attribute data.
5 6 7 |
# File 'lib/gnip_api/apis/power_track/buffer.rb', line 5 def data @data end |
permalink #terminator ⇒ Object (readonly)
Returns the value of attribute terminator.
5 6 7 |
# File 'lib/gnip_api/apis/power_track/buffer.rb', line 5 def terminator @terminator end |
Instance Method Details
permalink #consume!(chars) ⇒ Object
[View source]
32 33 34 |
# File 'lib/gnip_api/apis/power_track/buffer.rb', line 32 def consume! chars @data[0..chars-1] = '' end |
permalink #insert!(chunk) ⇒ Object
[View source]
16 17 18 |
# File 'lib/gnip_api/apis/power_track/buffer.rb', line 16 def insert! chunk @data << chunk end |
permalink #read! ⇒ Object
[View source]
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/gnip_api/apis/power_track/buffer.rb', line 20 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 |
permalink #size ⇒ Object
[View source]
12 13 14 |
# File 'lib/gnip_api/apis/power_track/buffer.rb', line 12 def size @data.size end |