Class: MmGPS::Buffer
- Inherits:
-
Object
- Object
- MmGPS::Buffer
- Includes:
- Enumerable
- Defined in:
- lib/mm_gps/mm_gps_buffer.rb
Overview
A general abstraction for dealing with character streams.
Instance Attribute Summary collapse
-
#buffer ⇒ Object
readonly
Returns the value of attribute buffer.
-
#fiber ⇒ Object
readonly
Returns the value of attribute fiber.
-
#separator ⇒ Object
Returns the value of attribute separator.
-
#stop_packet ⇒ Object
readonly
Returns the value of attribute stop_packet.
Instance Method Summary collapse
-
#clear ⇒ String
Clear the #buffer and return its last content.
-
#each {|pkt| ... } ⇒ Enumerator
Iterates a block over incoming packets.
-
#initialize(sep = "\xFF") ⇒ Buffer
constructor
A new instance of Buffer.
-
#next ⇒ String
Return the next available packet.
-
#update ⇒ Object
Call the block set with #when_updating and queues its returned byte into #buffer.
-
#when_updating(&block) ⇒ Object
Sets the block to be executed for updating the #buffer.
Constructor Details
#initialize(sep = "\xFF") ⇒ Buffer
Returns a new instance of Buffer.
20 21 22 23 24 25 26 |
# File 'lib/mm_gps/mm_gps_buffer.rb', line 20 def initialize(sep="\xFF") @update = lambda { empty } @encoding = Encoding::BINARY fiber_init self.separator = sep self.clear end |
Instance Attribute Details
#buffer ⇒ Object (readonly)
Returns the value of attribute buffer.
18 19 20 |
# File 'lib/mm_gps/mm_gps_buffer.rb', line 18 def buffer @buffer end |
#fiber ⇒ Object (readonly)
Returns the value of attribute fiber.
18 19 20 |
# File 'lib/mm_gps/mm_gps_buffer.rb', line 18 def fiber @fiber end |
#separator ⇒ Object
Returns the value of attribute separator.
17 18 19 |
# File 'lib/mm_gps/mm_gps_buffer.rb', line 17 def separator @separator end |
#stop_packet ⇒ Object (readonly)
Returns the value of attribute stop_packet.
17 18 19 |
# File 'lib/mm_gps/mm_gps_buffer.rb', line 17 def stop_packet @stop_packet end |
Instance Method Details
#clear ⇒ String
Clear the #buffer and return its last content.
38 39 40 41 42 |
# File 'lib/mm_gps/mm_gps_buffer.rb', line 38 def clear tmp = @buffer @buffer = empty return tmp end |
#each {|pkt| ... } ⇒ Enumerator
Iterates a block over incoming packets
74 75 76 77 78 79 |
# File 'lib/mm_gps/mm_gps_buffer.rb', line 74 def each return enum_for(:each) unless block_given? loop do yield self.next end end |
#next ⇒ String
Return the next available packet
65 66 67 |
# File 'lib/mm_gps/mm_gps_buffer.rb', line 65 def next @fiber.resume end |
#update ⇒ Object
Call the block set with #when_updating and queues its returned byte into #buffer
58 59 60 |
# File 'lib/mm_gps/mm_gps_buffer.rb', line 58 def update @buffer << (@update.call || empty) end |
#when_updating(&block) ⇒ Object
53 54 55 |
# File 'lib/mm_gps/mm_gps_buffer.rb', line 53 def when_updating(&block) @update = block end |