class ArcFurnace::AbstractJoin

Public Class Methods

new(source: , hash:, key_column: nil) click to toggle source

The source is a source, the hash is a hash, and one can optionally pass the key column to get the primary key for each source entity, the default is equijoin semantics–the key of the hash is used.

# File lib/arc-furnace/abstract_join.rb, line 10
def initialize(source: , hash:, key_column: nil)
  if source.is_a?(::ArcFurnace::Source) && hash.is_a?(::ArcFurnace::Hash)
    @hash = hash
    @source = source
    @key_column = key_column || hash.key_column
  else
    raise 'Must be passed one Hash and one Source!'
  end
end

Public Instance Methods

advance() click to toggle source
# File lib/arc-furnace/abstract_join.rb, line 27
def advance
  raise "Unimplemented!"
end
value() click to toggle source
# File lib/arc-furnace/abstract_join.rb, line 20
def value
  if @value.nil? && !empty?
    advance
  end
  @value
end

Protected Instance Methods

merge_source_row(source_row) click to toggle source
# File lib/arc-furnace/abstract_join.rb, line 35
def merge_source_row(source_row)
  key = source_row[key_column]
  if key
    if hash_value = hash.get(key)
      hash_value = hash_value.deep_dup
      source_row.each do |key, value|
        hash_value[key] = value
      end
      @value = hash_value
      true
    else
      error_handler.missing_hash_key(source_row: source_row, key: key, node_id: node_id)
      false
    end
  else
    error_handler.missing_join_key(source_row: source_row, node_id: node_id)
  end
end