Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/hash.rb
Instance Method Summary collapse
-
#keys_to_sym ⇒ Object
used by HoneyDo methods.
-
#split_compound_values(delimiter = "|") ⇒ Object
if a value is non-scalar, i.e.
Instance Method Details
#keys_to_sym ⇒ Object
used by HoneyDo methods
3 4 5 6 7 |
# File 'lib/hash.rb', line 3 def keys_to_sym sym_key_hash = Hash.new() self.each { |k, v| sym_key_hash[k.to_sym] = v} return sym_key_hash end |
#split_compound_values(delimiter = "|") ⇒ Object
if a value is non-scalar, i.e. not a single value but a list of delimited ones, put each into its own pair
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/hash.rb', line 10 def split_compound_values(delimiter = "|") new_pairs = Hash.new() self.each do |key, value| if value.include?(delimiter) value_array = value.split(delimiter) value_array.each_index do |i| unless new_pairs.has_key?(key) new_pairs[key] = value_array[i] # first value goes in pair with original key name else new_pairs[(key.to_s + "_" + i.to_s).to_sym] = value_array[i] # add index, starting with 1, to new key names for remaining values end end end end #merge in new pairs, which replaces any that had a compound value with a pair having the original key and the first value only return self.merge(new_pairs) end |