From: Josh Cheek Date: 2010-06-02T16:05:01+09:00 Subject: Re: Parsing geonames --0016e6d7e9a33aa4ae048806b539 Content-Type: text/plain; charset=ISO-8859-1 On Wed, Jun 2, 2010 at 1:30 AM, 12 34 wrote: > Michael Fellinger wrote: > > On Wed, Jun 2, 2010 at 2:57 PM, 12 34 wrote: > >> 41.505928,-81.594582 > > > > iota ~ % irb > >>> require 'geonames' > > => true > >>> places = Geonames::WebService.find_nearby_place_name(41.505928, > -81.594582) > > => [# > @alternate_names=nil, @latitude=41.5089406, @longitude=-81.5981817, > > @geoname_id="5161005", @country_code="US", @country_name="United > > States", @feature_class="P", @feature_code="PPLX", > > @feature_class_name=nil, @feature_code_name=nil, @population=nil, > > @elevation=nil, @distance=0.4495>] > >>> places.first.country_name > > => "United States" > > Thanks. I had tried places.country_name among others. Why the "first"? > > Because places is an array (think a list of geonames). You can tell it is an Array because it is surrounded by brackets. You have to tell it which element in the Array you are interested in, in this case the one at index zero (the first index). http://ruby-doc.org/core/classes/Array.html > places_nearby[0].country_code works too. > > The docs didn't suggest how to parse the result. > > Thank you for the answers, but I'm not sure why it's working. But I can > proceed. > > -- > Posted via http://www.ruby-forum.com/. > > --0016e6d7e9a33aa4ae048806b539--