Module: Brian::Lookup
- Defined in:
- lib/brian/lookup.rb
Class Method Summary collapse
- .build_lookup(hashes) ⇒ Object
- .lookup_from_hash(hash) ⇒ Object
- .to_array(lookup, hash) ⇒ Object
- .to_hash(lookup, array) ⇒ Object
Class Method Details
.build_lookup(hashes) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/brian/lookup.rb', line 3 def self.build_lookup(hashes) hash = hashes.reduce do |memo, hash| memo.merge(hash) end return Brian::Lookup.lookup_from_hash(hash) end |
.lookup_from_hash(hash) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/brian/lookup.rb', line 11 def self.lookup_from_hash(hash) lookup = {} index = 0 hash.keys.each do |k| lookup[k] = index index += 1 end return lookup end |
.to_array(lookup, hash) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/brian/lookup.rb', line 23 def self.to_array(lookup, hash) array = [] lookup.each_pair do |k,v| array[v] = hash.has_key?(k) ? hash[k] : 0 end return array end |
.to_hash(lookup, array) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/brian/lookup.rb', line 33 def self.to_hash(lookup, array) hash = {} lookup.each_pair do |k,v| hash[k] = array[v] end return hash end |