Class: ArcFurnace::Unfold
- Defined in:
- lib/arc-furnace/unfold.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Node
#error_handler, #node_id, #params
Instance Method Summary collapse
- #advance ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(source:) ⇒ Unfold
constructor
A new instance of Unfold.
-
#unfold(row) ⇒ Object
Given a row from the source, produce the unfolded rows as a result.
- #value ⇒ Object
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
#advance ⇒ Object
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
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 |
#value ⇒ Object
16 17 18 19 20 21 |
# File 'lib/arc-furnace/unfold.rb', line 16 def value if @value.nil? && !empty? advance end @value end |