Class: NdTransmission::Base
- Inherits:
-
Object
- Object
- NdTransmission::Base
- Defined in:
- lib/nd_transmission/base.rb
Instance Attribute Summary collapse
-
#chunk_size ⇒ Object
Returns the value of attribute chunk_size.
-
#dest ⇒ Object
Returns the value of attribute dest.
-
#origin ⇒ Object
Returns the value of attribute origin.
Instance Method Summary collapse
- #in_chunks ⇒ Object
-
#initialize(config) ⇒ Base
constructor
A new instance of Base.
- #origins ⇒ Object
- #transmit ⇒ Object
Constructor Details
#initialize(config) ⇒ Base
Returns a new instance of Base.
5 6 7 8 |
# File 'lib/nd_transmission/base.rb', line 5 def initialize config self.chunk_size = config.delete(:chunk_size) || 1 self.origin, self.dest = config.keys.first, config.values.first end |
Instance Attribute Details
#chunk_size ⇒ Object
Returns the value of attribute chunk_size.
3 4 5 |
# File 'lib/nd_transmission/base.rb', line 3 def chunk_size @chunk_size end |
#dest ⇒ Object
Returns the value of attribute dest.
3 4 5 |
# File 'lib/nd_transmission/base.rb', line 3 def dest @dest end |
#origin ⇒ Object
Returns the value of attribute origin.
3 4 5 |
# File 'lib/nd_transmission/base.rb', line 3 def origin @origin end |
Instance Method Details
#in_chunks ⇒ Object
16 17 18 19 20 |
# File 'lib/nd_transmission/base.rb', line 16 def in_chunks return to_enum(__callee__) unless block_given? yield origins.shift(chunk_size) while origins.any? end |
#origins ⇒ Object
22 23 24 |
# File 'lib/nd_transmission/base.rb', line 22 def origins @origins ||= origin.to_transmit end |
#transmit ⇒ Object
10 11 12 13 14 |
# File 'lib/nd_transmission/base.rb', line 10 def transmit in_chunks do |chunk| dest.receive chunk end end |