Module: ImlClient::Util

Extended by:
Util
Included in:
Util
Defined in:
lib/iml_client/util.rb

Instance Method Summary collapse

Instance Method Details

#array_wrap(value) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/iml_client/util.rb', line 30

def array_wrap(value)
  if value.is_a? Array
    return value
  elsif value.nil?
    return []
  else
    return [value]
  end
end

#blank?(value) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
28
# File 'lib/iml_client/util.rb', line 24

def blank?(value)
  value.nil? || 
  (value.is_a?(String) && value.strip == '') ||
  ((value.is_a?(Array) || (value.is_a?(Hash))) && value.empty?)
end

#hash_value_at_keypath(hash, keypath) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/iml_client/util.rb', line 14

def hash_value_at_keypath(hash, keypath)
  if keypath.length == 0 || !hash.is_a?(Hash)
    return nil
  elsif keypath.length == 1
    return hash[keypath[0]]
  else
    return hash_value_at_keypath hash[keypath[0]], keypath[1..-1]        
  end
end

#symbolize_keys(hash) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/iml_client/util.rb', line 6

def symbolize_keys(hash)
  result = {}
  hash.each do |key, value|
    result[key.to_sym] = value
  end
  result
end