Sha256: 929516cc0173a2dff0b901a40705af7a02ee0e97b318809609f0e3df1ab8bfa4

Contents?: true

Size: 897 Bytes

Versions: 24

Compression:

Stored size: 897 Bytes

Contents

module Lita
  # Handy utilities used by other Lita classes.
  module Util
    class << self
      # Returns a hash with any symbol keys converted to strings.
      # @param hash [Hash] The hash to convert.
      # @return [Hash] The converted hash.
      def stringify_keys(hash)
        result = {}
        hash.each_key { |key| result[key.to_s] = hash[key] }
        result
      end

      # Transforms a camel-cased string into a snaked-cased string. Taken from +ActiveSupport.+
      # @param camel_cased_word [String] The word to transform.
      # @return [String] The transformed word.
      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
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
lita-4.8.0 lib/lita/util.rb
lita-4.8.0.beta1 lib/lita/util.rb
lita-4.7.1 lib/lita/util.rb
lita-4.7.0 lib/lita/util.rb
lita-4.6.1 lib/lita/util.rb
lita-4.6.0 lib/lita/util.rb
lita-4.5.0 lib/lita/util.rb
lita-4.4.3 lib/lita/util.rb
lita-4.4.2 lib/lita/util.rb
lita-4.4.1 lib/lita/util.rb
lita-4.4.0 lib/lita/util.rb
lita-4.3.2 lib/lita/util.rb
lita-4.3.1 lib/lita/util.rb
lita-4.3.0 lib/lita/util.rb
lita-4.2.1 lib/lita/util.rb
lita-4.2.0 lib/lita/util.rb
lita-4.1.0 lib/lita/util.rb
lita-4.0.4 lib/lita/util.rb
lita-4.0.3 lib/lita/util.rb
lita-4.0.2 lib/lita/util.rb