module RocketChat::Util
Rocket.Chat generic utility functions
Public Instance Methods
camelize(string)
click to toggle source
Camelize a string or symbol @param [String/Symbol] string A string or symbol @return a camelized string
# File lib/rocket_chat/util.rb, line 49 def camelize(string) string.to_s.gsub(/_([a-z])/) { Regexp.last_match(1).upcase } end
slice_hash(hash, *keys)
click to toggle source
Slice keys from hash @param [Hash] hash A hash to slice key/value pairs from @param [Array] *keys The keys to be sliced @return Hash filtered by keys
# File lib/rocket_chat/util.rb, line 34 def slice_hash(hash, *keys) return {} if keys.length.zero? new_hash = {} hash.each do |key, value| new_hash[key] = value if keys.include? key end new_hash end
stringify_hash_keys(hash)
click to toggle source
Stringify symbolized hash keys @param [Hash] hash A string/symbol keyed hash @return Stringified hash
# File lib/rocket_chat/util.rb, line 15 def stringify_hash_keys(hash) new_hash = {} hash.each do |key, value| new_hash[key.to_s] = if value.is_a? Hash stringify_hash_keys value else value end end new_hash end