Sha256: c90b01f6c518574961cd7a7e4d14f6bc7af99e2a99c7b0360f49cb21b2028281

Contents?: true

Size: 1.13 KB

Versions: 7

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

module RocketChat
  #
  # Rocket.Chat generic utility functions
  #
  module Util
    module_function

    #
    # Stringify symbolized hash keys
    # @param [Hash] hash A string/symbol keyed hash
    # @return Stringified hash
    #
    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

    #
    # 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
    #
    def slice_hash(hash, *keys)
      return {} if keys.empty?

      new_hash = {}
      hash.each do |key, value|
        new_hash[key] = value if keys.include? key
      end
      new_hash
    end

    #
    # Camelize a string or symbol
    # @param [String/Symbol] string A string or symbol
    # @return a camelized string
    #
    def camelize(string)
      string.to_s.gsub(/_([a-z])/) { Regexp.last_match(1).upcase }
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rocketchat-0.3.1 lib/rocket_chat/util.rb
rocketchat-0.2.7 lib/rocket_chat/util.rb
rocketchat-0.2.6 lib/rocket_chat/util.rb
rocketchat-0.2.5 lib/rocket_chat/util.rb
rocketchat-0.2.4 lib/rocket_chat/util.rb
rocketchat-0.2.3 lib/rocket_chat/util.rb
rocketchat-0.2.2 lib/rocket_chat/util.rb