Module: ElabsMatchers::Helpers::NormalizeKeys

Defined in:
lib/elabs_matchers/helpers/normalize_keys.rb

Instance Method Summary collapse

Instance Method Details

#normalize_keys(hash) ⇒ Object

Normalizes a hash so that it can be described in a more human friendly manner.

Examples:

# Or in a Cucumber table: Given the following people:

| First name | Last name |
| Douglas    | Adams     |

Parameters:

  • hash (Hash)

    A hash of human-friendly key and value pairs.



20
21
22
23
24
25
# File 'lib/elabs_matchers/helpers/normalize_keys.rb', line 20

def normalize_keys(hash)
  hash.inject(HashWithIndifferentAccess.new) do |new_hash, (key, value)|
    new_hash[key.parameterize(separator: "_")] = value
    new_hash
  end
end