Class: ArcFurnace::Unfold

Inherits:
Source show all
Defined in:
lib/arc-furnace/unfold.rb

Direct Known Subclasses

BlockUnfold

Instance Attribute Summary

Attributes inherited from Node

#error_handler, #node_id, #params

Instance Method Summary collapse

Methods inherited from Source

#close, #finalize, #prepare, #row

Constructor Details

#initialize(source:) ⇒ Unfold

Returns a new instance of Unfold.



11
12
13
14
# File 'lib/arc-furnace/unfold.rb', line 11

def initialize(source:)
  @source = source
  @value = nil
end

Instance Method Details

#advanceObject



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/arc-furnace/unfold.rb', line 33

def advance
  while (unfolded.nil? || unfolded.empty?) && !source.empty?
    # Use reverse since we want to process in-order, but, #pop is much faster than #unshift
    @unfolded = unfold(source.row.deep_dup)
    unfolded.reverse!
  end
  if unfolded && !unfolded.empty?
    @value = unfolded.pop
  else
    @value = nil
  end
end

#empty?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/arc-furnace/unfold.rb', line 29

def empty?
  @value.nil? && source.empty?
end

#unfold(row) ⇒ Object

Given a row from the source, produce the unfolded rows as a result. This method must return an array.



25
26
27
# File 'lib/arc-furnace/unfold.rb', line 25

def unfold(row)
  raise "Unimplemented!"
end

#valueObject



16
17
18
19
20
21
# File 'lib/arc-furnace/unfold.rb', line 16

def value
  if @value.nil? && !empty?
    advance
  end
  @value
end