Class: Kiba::Extend::Utils::LookupHash
- Inherits:
-
Object
- Object
- Kiba::Extend::Utils::LookupHash
- Defined in:
- lib/kiba/extend/utils/lookup_hash.rb
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
Instance Method Summary collapse
-
#add_record(record) ⇒ Object
-
#initialize(keycolumn:) ⇒ LookupHash
constructor
A new instance of LookupHash.
Constructor Details
#initialize(keycolumn:) ⇒ LookupHash
Returns a new instance of LookupHash.
12 13 14 15 |
# File 'lib/kiba/extend/utils/lookup_hash.rb', line 12 def initialize(keycolumn:) @keycolumn = keycolumn @hash = {} end |
Instance Attribute Details
#hash ⇒ Object (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
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 |