Class: ArcFurnace::EnumeratorSource

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

Instance Attribute Summary collapse

Attributes inherited from Node

#error_handler, #node_id, #params

Instance Method Summary collapse

Methods inherited from Source

#close, #finalize, #prepare, #row

Constructor Details

#initializeEnumeratorSource

Returns a new instance of EnumeratorSource.



9
10
11
12
13
# File 'lib/arc-furnace/enumerator_source.rb', line 9

def initialize
  @enumerator = build_enumerator
  preprocess
  advance
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



7
8
9
# File 'lib/arc-furnace/enumerator_source.rb', line 7

def value
  @value
end

Instance Method Details

#advanceObject



26
27
28
29
30
31
32
33
34
# File 'lib/arc-furnace/enumerator_source.rb', line 26

def advance
  @value =
    begin
      enumerator.next if enumerator
    rescue StopIteration
      @enumerator = nil
      nil
    end
end

#empty?Boolean

Is this source empty?

Returns:

  • (Boolean)


22
23
24
# File 'lib/arc-furnace/enumerator_source.rb', line 22

def empty?
  !value
end

#preprocessObject

Called after setting up the enumerator but before advancing it Use this to extract header rows for instance.



17
18
19
# File 'lib/arc-furnace/enumerator_source.rb', line 17

def preprocess
  # nothing
end