Class: Thoreau::HashUtil
- Inherits:
-
Object
- Object
- Thoreau::HashUtil
- Defined in:
- lib/thoreau/service/util.rb
Class Method Summary collapse
-
.normalize_props(hash, prop_map, include_all_normalized_props = true) ⇒ Object
prop_map is a map from canonical property name to all versions.
- .one_of_these(hash, pick_one_of_these_keys, default_value = nil) ⇒ Object
Class Method Details
.normalize_props(hash, prop_map, include_all_normalized_props = true) ⇒ Object
prop_map is a map from canonical property name to all versions
18 19 20 21 22 23 24 |
# File 'lib/thoreau/service/util.rb', line 18 def self.normalize_props(hash, prop_map, include_all_normalized_props = true) prop_map.reduce(Hash.new) do |memo, (k, v)| value = one_of_these(hash, v, include_all_normalized_props ? nil : :secret_default_value) memo[k] = value unless value == :secret_default_value memo end end |
.one_of_these(hash, pick_one_of_these_keys, default_value = nil) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/thoreau/service/util.rb', line 26 def self.one_of_these(hash, pick_one_of_these_keys, default_value = nil) keys_present = pick_one_of_these_keys.intersection hash.keys if keys_present.size > 1 logger.error "Only of of these keys is allowed: #{keys_present.to_sentence}" end pick_one_of_these_keys.each do |k| return hash[k] if hash.key?(k) end default_value end |