Class: LazierData::Processor::ChildEachSlice

Inherits:
Object
  • Object
show all
Defined in:
lib/lazier_data/processor/child_each_slice.rb

Constant Summary collapse

NOTHING =
:_lazier_data_nothing

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(upstream, downstream, batch_size, input_path, &block) ⇒ ChildEachSlice

Returns a new instance of ChildEachSlice.



10
11
12
13
14
15
16
# File 'lib/lazier_data/processor/child_each_slice.rb', line 10

def initialize(upstream, downstream, batch_size, input_path, &block)
  @upstream = upstream
  @downstream = downstream
  @batch_size = batch_size
  @input_path = input_path
  @block = block
end

Instance Attribute Details

#batch_sizeObject (readonly)

Returns the value of attribute batch_size.



8
9
10
# File 'lib/lazier_data/processor/child_each_slice.rb', line 8

def batch_size
  @batch_size
end

#blockObject (readonly)

Returns the value of attribute block.



8
9
10
# File 'lib/lazier_data/processor/child_each_slice.rb', line 8

def block
  @block
end

#downstreamObject (readonly)

Returns the value of attribute downstream.



8
9
10
# File 'lib/lazier_data/processor/child_each_slice.rb', line 8

def downstream
  @downstream
end

#input_pathObject (readonly)

Returns the value of attribute input_path.



8
9
10
# File 'lib/lazier_data/processor/child_each_slice.rb', line 8

def input_path
  @input_path
end

#upstreamObject (readonly)

Returns the value of attribute upstream.



8
9
10
# File 'lib/lazier_data/processor/child_each_slice.rb', line 8

def upstream
  @upstream
end

Instance Method Details

#callObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/lazier_data/processor/child_each_slice.rb', line 18

def call
  slicer.each_slice(batch_size) do |raw_yielded|
    items = raw_yielded.map(&:first)
    yielders = raw_yielded.last[3]
    @block.call(items, *yielders)
    raw_yielded.each do |_, root_item, item_store, _|
      next if root_item == NOTHING

      downstream << [root_item, item_store]
    end
  end
end