Class: Kiba::Extend::Utils::LookupHash

Inherits:
Object
  • Object
show all
Defined in:
lib/kiba/extend/utils/lookup_hash.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keycolumn:) ⇒ LookupHash

Returns a new instance of LookupHash.

Parameters:

  • keycolumn (Symbol)

    field name on which rows are grouped/looked up



12
13
14
15
# File 'lib/kiba/extend/utils/lookup_hash.rb', line 12

def initialize(keycolumn:)
  @keycolumn = keycolumn
  @hash = {}
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



9
10
11
# File 'lib/kiba/extend/utils/lookup_hash.rb', line 9

def hash
  @hash
end

Instance Method Details

#add_record(record) ⇒ Object

Parameters:

  • record (Hash{Symbol => String})


18
19
20
21
# File 'lib/kiba/extend/utils/lookup_hash.rb', line 18

def add_record(record)
  key = record.fetch(keycolumn, nil)
  hash.key?(key) ? hash[key] << record : hash[key] = [record]
end