Class: KondutoUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/konduto-ruby/konduto_utils.rb

Class Method Summary collapse

Class Method Details

.array_to_hash(arr) ⇒ Object


2
3
4
# File 'lib/konduto-ruby/konduto_utils.rb', line 2

def self.array_to_hash arr
  arr.map{ |pair| Hash[*pair] }
end

.deep_symbolize_keys(hash) ⇒ Object


10
11
12
13
14
# File 'lib/konduto-ruby/konduto_utils.rb', line 10

def self.deep_symbolize_keys hash
  return hash.inject({}){|memo,(k,v)| memo[k.to_sym] = deep_symbolize_keys(v); memo} if hash.is_a? Hash
  return hash.inject([]){|memo,v    | memo           << deep_symbolize_keys(v); memo} if hash.is_a? Array
  return hash
end

.remove_nil_keys_from_hash(hash) ⇒ Object


6
7
8
# File 'lib/konduto-ruby/konduto_utils.rb', line 6

def self.remove_nil_keys_from_hash hash
  hash.delete_if { |k, v| v.nil? || (v.respond_to?(:empty?) && v.empty?) }
end