class HashWithDoubleAccess

Public Instance Methods

call() click to toggle source
# File lib/ground/activity/hash_with_double_access.rb, line 3
def call
  str_h = access_with(data, :to_s)
  sym_h = access_with(data, :to_sym)
  sym_h.merge str_h
end

Private Instance Methods

access_with(d, m) click to toggle source
# File lib/ground/activity/hash_with_double_access.rb, line 12
def access_with(d, m)
  tmp_h = {}
  d.each {|k, v|
    if v.is_a? Hash
      tmp_h[k.send(m)] = access_with(v, m)
    elsif v.is_a? Array
      v_dup = v.dup
      v_dup.each_with_index {|item, index| v_dup[index] = access_with(item, m) if item.is_a? Hash}
      tmp_h[k.send(m)] = v_dup
    else
      tmp_h[k.send(m)] = v
    end
  }
  tmp_h
end