Array Decode

Hi folks.

Been returned an array of a single item thats really confusing. Any
input as to how I tackle this thing would be truly appreciated.

[#<Geocoder::Result::Google:0x007fd4e382dd58
@data={“address_components”=>[{“long_name”=>“1600”,
“short_name”=>“1600”, “types”=>[“street_number”]},
{“long_name”=>“Amphitheatre Parkway”, “short_name”=>“Amphitheatre Pkwy”,
“types”=>[“route”]}, {“long_name”=>“Mountain View”,
“short_name”=>“Mountain View”, “types”=>[“locality”, “political”]},
{“long_name”=>“California”, “short_name”=>“CA”,
“types”=>[“administrative_area_level_1”, “political”]},
{“long_name”=>“United States”, “short_name”=>“US”, “types”=>[“country”,
“political”]}, {“long_name”=>“94043”, “short_name”=>“94043”,
“types”=>[“postal_code”]}], “formatted_address”=>“1600 Amphitheatre
Parkway, Mountain View, CA 94043, USA”,
“geometry”=>{“location”=>{“lat”=>37.4219985, “lng”=>-122.0839544},
“location_type”=>“ROOFTOP”,
“viewport”=>{“northeast”=>{“lat”=>37.4233474802915,
“lng”=>-122.0826054197085}, “southwest”=>{“lat”=>37.4206495197085,
“lng”=>-122.0853033802915}}}, “types”=>[“street_address”]},
@cache_hit=nil>]

Im new to Ruby but not coding. Im trying to reach into location lat and
lon. The issue I see here is that it begins with a commentwhich gets me
nowhere. Also, nested nodes, Im not sure how to bring this up. Theres
an instance variable thats holding the information I need, but I cant
get into that var.

Any insight appreciated.

Cheers

Subject: Array Decode
Date: mer 05 feb 14 11:18:52 -0500

Quoting BeeRich ([email protected]):

Been returned an array of a single item that???s really confusing.
Any input as to how I tackle this thing would be truly appreciated.

From your output, it appears that the object includes a hash called
‘data’. If you use pp, you can have a pretty-print of it:

require ‘pp’
pp .data

From what I see of your output, you should be able to get lat and long
with this syntax:

.data[‘geometry’][‘location’][‘lat’]
.data[‘geometry’][‘location’][‘lng’]

but you need to test that.

If you do not know exactly what a hash is, you can type

ri Hash

on your terminal.

Carlo

Thanks for the reply.

Turns out I wasnt aware of the structure of the inspect method. The
data is inside the @data. That text threw me off as it doesnt have a
proper structure.

res = Geocoder.search(i).first

gets the job done.

Ya hashes from my other language are called maps. Been writing them for
over a decade. This inspect method completely stumped me.

Cheers

Lasso

WHat’s your other language? Erlang?