class ArcFurnace::Hash

Attributes

key_column[R]

Public Class Methods

new(source: , key_column:) click to toggle source
# File lib/arc-furnace/hash.rb, line 8
def initialize(source: , key_column:)
  @source = source
  @key_column = key_column
  @hash = {}
end

Public Instance Methods

each(&block) click to toggle source

Pass a block that accepts two argument, the join key for each value and the value

# File lib/arc-furnace/hash.rb, line 16
def each(&block)
  hash.each(&block)
end
finalize() click to toggle source

Called at the end of processing all rows; do any clean-up or state saving here.

# File lib/arc-furnace/hash.rb, line 21
def finalize

end
get(primary_key) click to toggle source
# File lib/arc-furnace/hash.rb, line 41
def get(primary_key)
  hash[primary_key]
end
prepare() click to toggle source
# 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