Module: Hsdq::Utilities

Included in:
Hsdq
Defined in:
lib/hsdq/utilities.rb

Instance Method Summary collapse

Instance Method Details

#deep_symbolize(a_hash) ⇒ Hash

utility method to symbolize the keys of a hash

Parameters:

  • the (Hash, #a_hash)

    hash to be converted

Returns:

  • (Hash)

    with all keys as symbol



8
9
10
# File 'lib/hsdq/utilities.rb', line 8

def deep_symbolize(a_hash)
  JSON.parse(JSON[a_hash], symbolize_names: true)
end

#snakify(string) ⇒ String

utility method (equivalent to Rails underscore)

Parameters:

  • the (String, #string)

    string to be transformed ie: class/constant name

Returns:

  • (String)

    underscored string all in lowercase



15
16
17
# File 'lib/hsdq/utilities.rb', line 15

def snakify(string)
  string.split(/(?=[A-Z])/).map(&:downcase).join('_')
end