I have a simple collection:
{
:metadata=>{:latitude=>25.86222, :longitude=>-80.27901},
:components=>{:primary_number=>"4390", :street_predirection=>"E"},
:analysis=>{:footnotes=>"N#", :dpv_footnotes=>"AABB"}
}
I want this:
{:latitude=>25.86222, :longitude=>-80.27901, :primary_number=>"4390", :street_predirection=>"E",:footnotes=>"N#", :dpv_footnotes=>"AABB" }
In other words, I don't care about the first-level keys. I just care about everything else and I want to iterate through everything else as such:
my_hash.each {|k,v| ... }
I looked through the Hash class and felt that values_at
will help simplify this task. So I tried:
Record.first.mail_validation
# => {:metadata=>{:county_name=>"Miami-Dade", :latitude=>25.86222, :longitude=>-80.27901, :time_zone=>"Eastern", :rdi=>"Residential"}, :components=>{:primary_number=>"4390", :street_predirection=>"E", :street_name=>"2nd", :street_suffix=>"Ave", :secondary_number=>nil, :secondary_designator=>nil, :city_name=>"Hialeah", :state_abbreviation=>"FL", :zipcode=>"33013", :plus4_code=>"2249"}, :analysis=>{:footnotes=>"N#", :dpv_footnotes=>"AABB", :dpv_match_code=>"Y"}}
Record.first.mail_validation.keys
# => [:metadata, :components, :analysis]
This returns no results, since the argument to values_at
is a string and I pass an array:
Record.first.mail_validation.values_at(Record.first.mail_validation.keys)
# => [nil]
This doesn't work, because although I pass string as arguments to values_at
, the keys in the hash are symbols, not keys:
Record.first.mail_validation.values_at(Record.first.mail_validation.keys.join(", "))
# => [nil]
Any suggestions on this?