Module: Fountain::Util

Defined in:
lib/fountain/util.rb

Overview

Fountain generic utility functions

Class Method Summary collapse

Class Method Details

.slice_hash(hash, *keys) ⇒ Object

Slice keys from hash



34
35
36
37
38
39
40
41
42
# File 'lib/fountain/util.rb', line 34

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

.stringify_hash_keys(hash) ⇒ Object

Stringify symbolized hash keys



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fountain/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