Sha256: 66f15fc1b946b2da9be3922835ddcdab94598bf69661f55268ee9d4f7ae5f1fc

Contents?: true

Size: 773 Bytes

Versions: 1

Compression:

Stored size: 773 Bytes

Contents

module ElabsMatchers
  module Helpers
    module Common

      ##
      #
      # Normalizes a hash so that it can be described in a more
      # human friendly manner.
      #
      # @param [Hash] options     A hash of human-friendly key and value pairs.
      #
      # Examples:
      # normalize_keys({ "First name" => "Adam" }) => HashWithIndifferentAccess.new({ "first_name" => "adam" })
      #
      # # Or in a Cucumber table:
      # Given the following people:
      #  | First name | Last name |
      #  | Douglas    | Adams     |
      #

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
elabs_matchers-0.0.3 lib/elabs_matchers/helpers/common.rb