Module: Lita::Util

Defined in:
lib/lita/util.rb

Overview

Handy utilities used by other Lita classes.

Class Method Summary collapse

Class Method Details

.stringify_keys(hash) ⇒ Hash

Returns a hash with any symbol keys converted to strings.

Parameters:

  • hash (Hash)

    The hash to convert.

Returns:

  • (Hash)

    The converted hash.


8
9
10
11
12
# File 'lib/lita/util.rb', line 8

def stringify_keys(hash)
  result = {}
  hash.each_key { |key| result[key.to_s] = hash[key] }
  result
end

.underscore(camel_cased_word) ⇒ String

Transforms a camel-cased string into a snaked-cased string. Taken from ActiveSupport.

Parameters:

  • camel_cased_word (String)

    The word to transform.

Returns:

  • (String)

    The transformed word.


17
18
19
20
21
22
23
24
25
# File 'lib/lita/util.rb', line 17

def underscore(camel_cased_word)
  word = camel_cased_word.to_s.dup
  word.gsub!("::", "/")
  word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
  word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
  word.tr!("-", "_")
  word.downcase!
  word
end