Class: ArcFurnace::Hash
Direct Known Subclasses
Instance Attribute Summary collapse
-
#key_column ⇒ Object
readonly
Returns the value of attribute key_column.
Attributes inherited from Node
#error_handler, #node_id, #params
Instance Method Summary collapse
-
#each(&block) ⇒ Object
Pass a block that accepts two argument, the join key for each value and the value.
-
#finalize ⇒ Object
Called at the end of processing all rows; do any clean-up or state saving here.
- #get(primary_key) ⇒ Object
-
#initialize(source:, key_column:) ⇒ Hash
constructor
A new instance of Hash.
- #prepare ⇒ Object
Constructor Details
#initialize(source:, key_column:) ⇒ Hash
Returns a new instance of Hash.
8 9 10 11 12 |
# File 'lib/arc-furnace/hash.rb', line 8 def initialize(source: , key_column:) @source = source @key_column = key_column @hash = {} end |
Instance Attribute Details
#key_column ⇒ Object (readonly)
Returns the value of attribute key_column.
5 6 7 |
# File 'lib/arc-furnace/hash.rb', line 5 def key_column @key_column end |
Instance Method Details
#each(&block) ⇒ Object
Pass a block that accepts two argument, the join key for each value and the value
16 17 18 |
# File 'lib/arc-furnace/hash.rb', line 16 def each(&block) hash.each(&block) end |
#finalize ⇒ Object
Called at the end of processing all rows; do any clean-up or state saving here.
21 22 23 |
# File 'lib/arc-furnace/hash.rb', line 21 def finalize end |
#get(primary_key) ⇒ Object
41 42 43 |
# File 'lib/arc-furnace/hash.rb', line 41 def get(primary_key) hash[primary_key] end |
#prepare ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/arc-furnace/hash.rb', line 25 def prepare loop do break if source.empty? row = source.row key = row[key_column] if key if hash.include?(key) error_handler.duplicate_primary_key(duplicate_row: row, key: key, node_id: node_id) end hash[key] = row else error_handler.missing_primary_key(source_row: row, node_id: node_id) end end end |