Module: Kiba::Extend::Utils::Lookup
- Extended by:
- Lookup
- Included in:
- Lookup
- Defined in:
- lib/kiba/extend/utils/lookup.rb,
lib/kiba/extend/utils/lookup/row_sorter.rb,
lib/kiba/extend/utils/lookup/set_checker.rb,
lib/kiba/extend/utils/lookup/row_selector.rb,
lib/kiba/extend/utils/lookup/pair_equality.rb,
lib/kiba/extend/utils/lookup/multival_pairs.rb,
lib/kiba/extend/utils/lookup/pair_inclusion.rb,
lib/kiba/extend/utils/lookup/field_emptiness.rb,
lib/kiba/extend/utils/lookup/criteria_checker.rb,
lib/kiba/extend/utils/lookup/row_selector_by_hash.rb,
lib/kiba/extend/utils/lookup/row_selector_by_lambda.rb
Defined Under Namespace
Classes: CriteriaChecker, FieldEmptiness, MultivalPairs, PairEquality, PairInclusion, RowSelector, RowSelectorByHash, RowSelectorByLambda, RowSorter, SetChecker
Instance Method Summary collapse
-
#csv_to_hash(file:, keycolumn:, csvopt: Kiba::Extend.csvopts) ⇒ Hash
Creates hash with keycolumn value as key and array of csv-rows-as-hashes as the value.
-
#enum_to_hash(enum:, keycolumn:) ⇒ Hash
Turns any Enumerable where each item is a record/row hash into an expected lookup hash via Utils::LookupHash.
-
#from_job(jobkey:, lookup_on: nil, csvopt: Kiba::Extend.csvopts) ⇒ Hash
Creates hash from a registered job key outside of the context of job files setup.
Instance Method Details
#csv_to_hash(file:, keycolumn:, csvopt: Kiba::Extend.csvopts) ⇒ Hash
Creates hash with keycolumn value as key and array of csv-rows-as-hashes as the value
17 18 19 20 21 22 23 |
# File 'lib/kiba/extend/utils/lookup.rb', line 17 def csv_to_hash(file:, keycolumn:, csvopt: Kiba::Extend.csvopts) lookup = Kiba::Extend::Utils::LookupHash.new(keycolumn: keycolumn) CSV.foreach(File.(file), **csvopt) do |row| lookup.add_record(row.to_h) end lookup.hash end |
#enum_to_hash(enum:, keycolumn:) ⇒ Hash
Turns any Enumerable where each item is a record/row hash into an expected lookup hash via Utils::LookupHash
51 52 53 54 55 |
# File 'lib/kiba/extend/utils/lookup.rb', line 51 def enum_to_hash(enum:, keycolumn:) lookup = Kiba::Extend::Utils::LookupHash.new(keycolumn: keycolumn) enum.each { |row| lookup.add_record(row.to_h) } lookup.hash end |
#from_job(jobkey:, lookup_on: nil, csvopt: Kiba::Extend.csvopts) ⇒ Hash
Creates hash from a registered job key outside of the context of job files setup
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/kiba/extend/utils/lookup.rb', line 33 def from_job(jobkey:, lookup_on: nil, csvopt: Kiba::Extend.csvopts) entry = Kiba::Extend::Registry.entry_for(jobkey) path = entry.path lkup = lookup_on || entry.lookup_on unless lkup fail Kiba::Extend::NoLookupOnError.new(jobkey, "Lookup.from_job") end return {} unless Kiba::Extend::Job.output?(jobkey) csv_to_hash(file: path, keycolumn: lkup, csvopt: csvopt) end |