Class: NdTransmission::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/nd_transmission/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_sizeObject

Returns the value of attribute chunk_size.



3
4
5
# File 'lib/nd_transmission/base.rb', line 3

def chunk_size
  @chunk_size
end

#destObject

Returns the value of attribute dest.



3
4
5
# File 'lib/nd_transmission/base.rb', line 3

def dest
  @dest
end

#originObject

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_chunksObject



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

#originsObject



22
23
24
# File 'lib/nd_transmission/base.rb', line 22

def origins
  @origins ||= origin.to_transmit
end

#transmitObject



10
11
12
13
14
# File 'lib/nd_transmission/base.rb', line 10

def transmit
  in_chunks do |chunk|
    dest.receive chunk
  end
end