Class: GeoPlanet::Place
Instance Attribute Summary collapse
-
#admin1 ⇒ Object
readonly
Returns the value of attribute admin1.
-
#admin1_code ⇒ Object
readonly
Returns the value of attribute admin1_code.
-
#admin1_placetype ⇒ Object
readonly
Returns the value of attribute admin1_placetype.
-
#admin2 ⇒ Object
readonly
Returns the value of attribute admin2.
-
#admin2_code ⇒ Object
readonly
Returns the value of attribute admin2_code.
-
#admin2_placetype ⇒ Object
readonly
Returns the value of attribute admin2_placetype.
-
#admin3 ⇒ Object
readonly
Returns the value of attribute admin3.
-
#admin3_code ⇒ Object
readonly
Returns the value of attribute admin3_code.
-
#admin3_placetype ⇒ Object
readonly
Returns the value of attribute admin3_placetype.
-
#area_rank ⇒ Object
readonly
Returns the value of attribute area_rank.
-
#bounding_box ⇒ Object
readonly
Returns the value of attribute bounding_box.
-
#country ⇒ Object
readonly
long.
-
#country_code ⇒ Object
readonly
long.
-
#lang ⇒ Object
readonly
short.
-
#latitude ⇒ Object
(also: #lat)
readonly
Returns the value of attribute latitude.
-
#locality1 ⇒ Object
readonly
Returns the value of attribute locality1.
-
#locality1_placetype ⇒ Object
readonly
Returns the value of attribute locality1_placetype.
-
#locality2 ⇒ Object
readonly
Returns the value of attribute locality2.
-
#locality2_placetype ⇒ Object
readonly
Returns the value of attribute locality2_placetype.
-
#longitude ⇒ Object
(also: #lon)
readonly
Returns the value of attribute longitude.
-
#name ⇒ Object
readonly
short.
-
#placetype ⇒ Object
readonly
short.
-
#placetype_code ⇒ Object
readonly
short.
-
#pop_rank ⇒ Object
readonly
Returns the value of attribute pop_rank.
-
#postal ⇒ Object
readonly
long.
-
#uri ⇒ Object
readonly
short.
-
#version ⇒ Object
readonly
short or long.
-
#woeid ⇒ Object
readonly
short.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(woe_or_attrs, options = {}) ⇒ Place
constructor
Instance methods.
- #initialize_with_attrs(attrs) ⇒ Object
- #initialize_with_woe(woe, options = {}) ⇒ Object
- #inspect ⇒ Object
- #to_i ⇒ Object
- #to_s ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(woe_or_attrs, options = {}) ⇒ Place
Instance methods
46 47 48 49 50 51 52 53 |
# File 'lib/geoplanet/place.rb', line 46 def initialize(woe_or_attrs, = {}) case woe_or_attrs when Integer then initialize_with_woe(woe_or_attrs, ) when Hash then initialize_with_attrs(woe_or_attrs) else raise ArgumentError end end |
Instance Attribute Details
#admin1 ⇒ Object (readonly)
Returns the value of attribute admin1.
9 10 11 |
# File 'lib/geoplanet/place.rb', line 9 def admin1 @admin1 end |
#admin1_code ⇒ Object (readonly)
Returns the value of attribute admin1_code.
9 10 11 |
# File 'lib/geoplanet/place.rb', line 9 def admin1_code @admin1_code end |
#admin1_placetype ⇒ Object (readonly)
Returns the value of attribute admin1_placetype.
9 10 11 |
# File 'lib/geoplanet/place.rb', line 9 def admin1_placetype @admin1_placetype end |
#admin2 ⇒ Object (readonly)
Returns the value of attribute admin2.
10 11 12 |
# File 'lib/geoplanet/place.rb', line 10 def admin2 @admin2 end |
#admin2_code ⇒ Object (readonly)
Returns the value of attribute admin2_code.
10 11 12 |
# File 'lib/geoplanet/place.rb', line 10 def admin2_code @admin2_code end |
#admin2_placetype ⇒ Object (readonly)
Returns the value of attribute admin2_placetype.
10 11 12 |
# File 'lib/geoplanet/place.rb', line 10 def admin2_placetype @admin2_placetype end |
#admin3 ⇒ Object (readonly)
Returns the value of attribute admin3.
11 12 13 |
# File 'lib/geoplanet/place.rb', line 11 def admin3 @admin3 end |
#admin3_code ⇒ Object (readonly)
Returns the value of attribute admin3_code.
11 12 13 |
# File 'lib/geoplanet/place.rb', line 11 def admin3_code @admin3_code end |
#admin3_placetype ⇒ Object (readonly)
Returns the value of attribute admin3_placetype.
11 12 13 |
# File 'lib/geoplanet/place.rb', line 11 def admin3_placetype @admin3_placetype end |
#area_rank ⇒ Object (readonly)
Returns the value of attribute area_rank.
14 15 16 |
# File 'lib/geoplanet/place.rb', line 14 def area_rank @area_rank end |
#bounding_box ⇒ Object (readonly)
Returns the value of attribute bounding_box.
8 9 10 |
# File 'lib/geoplanet/place.rb', line 8 def bounding_box @bounding_box end |
#country ⇒ Object (readonly)
long
7 8 9 |
# File 'lib/geoplanet/place.rb', line 7 def country @country end |
#country_code ⇒ Object (readonly)
long
7 8 9 |
# File 'lib/geoplanet/place.rb', line 7 def country_code @country_code end |
#lang ⇒ Object (readonly)
short
5 6 7 |
# File 'lib/geoplanet/place.rb', line 5 def lang @lang end |
#latitude ⇒ Object (readonly) Also known as: lat
Returns the value of attribute latitude.
8 9 10 |
# File 'lib/geoplanet/place.rb', line 8 def latitude @latitude end |
#locality1 ⇒ Object (readonly)
Returns the value of attribute locality1.
12 13 14 |
# File 'lib/geoplanet/place.rb', line 12 def locality1 @locality1 end |
#locality1_placetype ⇒ Object (readonly)
Returns the value of attribute locality1_placetype.
12 13 14 |
# File 'lib/geoplanet/place.rb', line 12 def locality1_placetype @locality1_placetype end |
#locality2 ⇒ Object (readonly)
Returns the value of attribute locality2.
13 14 15 |
# File 'lib/geoplanet/place.rb', line 13 def locality2 @locality2 end |
#locality2_placetype ⇒ Object (readonly)
Returns the value of attribute locality2_placetype.
13 14 15 |
# File 'lib/geoplanet/place.rb', line 13 def locality2_placetype @locality2_placetype end |
#longitude ⇒ Object (readonly) Also known as: lon
Returns the value of attribute longitude.
8 9 10 |
# File 'lib/geoplanet/place.rb', line 8 def longitude @longitude end |
#name ⇒ Object (readonly)
short
5 6 7 |
# File 'lib/geoplanet/place.rb', line 5 def name @name end |
#placetype ⇒ Object (readonly)
short
5 6 7 |
# File 'lib/geoplanet/place.rb', line 5 def placetype @placetype end |
#placetype_code ⇒ Object (readonly)
short
5 6 7 |
# File 'lib/geoplanet/place.rb', line 5 def placetype_code @placetype_code end |
#pop_rank ⇒ Object (readonly)
Returns the value of attribute pop_rank.
14 15 16 |
# File 'lib/geoplanet/place.rb', line 14 def pop_rank @pop_rank end |
#postal ⇒ Object (readonly)
long
7 8 9 |
# File 'lib/geoplanet/place.rb', line 7 def postal @postal end |
#uri ⇒ Object (readonly)
short
5 6 7 |
# File 'lib/geoplanet/place.rb', line 5 def uri @uri end |
#version ⇒ Object (readonly)
short or long
3 4 5 |
# File 'lib/geoplanet/place.rb', line 3 def version @version end |
#woeid ⇒ Object (readonly)
short
5 6 7 |
# File 'lib/geoplanet/place.rb', line 5 def woeid @woeid end |
Class Method Details
.get_then_parse(url) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/geoplanet/place.rb', line 26 def self.get_then_parse(url) results = JSON.parse get(url).to_s return results['places']['place'].map{|attrs| Place.new attrs} if results['places'] return Place.new(results['place']) if results['place'] nil rescue nil end |
.search(text, options = {}) ⇒ Object
Class methods
19 20 21 22 23 24 |
# File 'lib/geoplanet/place.rb', line 19 def self.search(text, = {}) text = URI.encode(text) url = build_url('places', .merge(:q => text, :format => 'json')) puts "Yahoo GeoPlanet: GET #{url}" if GeoPlanet.debug get_then_parse(url) end |
Instance Method Details
#initialize_with_attrs(attrs) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/geoplanet/place.rb', line 62 def initialize_with_attrs(attrs) @version = attrs['centroid'] ? 'long' : 'short' # short @woeid = attrs['woeid'] @placetype = attrs['placeTypeName'] @placetype_code = attrs['placeTypeName attrs']['code'] @name = attrs['name'] @uri = attrs['uri'] @lang = attrs['lang'] if version == 'long' # long @latitude = attrs['centroid']['latitude'] @longitude = attrs['centroid']['longitude'] @bounding_box = [ [ attrs['boundingBox']['southWest']['latitude'], attrs['boundingBox']['southWest']['longitude'] ], [ attrs['boundingBox']['northEast']['latitude'], attrs['boundingBox']['northEast']['longitude'] ], ] @country = attrs['country'] @country_code = attrs['country attrs']['code'] rescue nil @postal = attrs['postal'] @admin1 = attrs['admin1'] @admin1_code = attrs['admin1 attrs']['code'] rescue nil @admin1_placetype = attrs['admin1 attrs']['type'] rescue nil @admin2 = attrs['admin2'] @admin2_code = attrs['admin2 attrs']['code'] rescue nil @admin2_placetype = attrs['admin2 attrs']['type'] rescue nil @admin3 = attrs['admin3'] @admin3_code = attrs['admin3 attrs']['code'] rescue nil @admin3_placetype = attrs['admin3 attrs']['type'] rescue nil @locality1 = attrs['locality1'] @locality1_placetype = attrs['locality1 attrs']['type'] rescue nil @locality2 = attrs['locality2'] @locality2_placetype = attrs['locality2 attrs']['type'] rescue nil @pop_rank = attrs['popRank'] @area_rank = attrs['areaRank'] end self end |
#initialize_with_woe(woe, options = {}) ⇒ Object
55 56 57 58 59 |
# File 'lib/geoplanet/place.rb', line 55 def initialize_with_woe(woe, = {}) url = self.class.build_url("place/#{woe}", .merge(:format => "json")) puts "Yahoo GeoPlanet: GET #{url}" if GeoPlanet.debug initialize_with_attrs JSON.parse(Place.get(url))['place'] end |
#inspect ⇒ Object
121 122 123 |
# File 'lib/geoplanet/place.rb', line 121 def inspect "#<GeoPlanet::Place #{instance_variables.map{|ivar| "#{ivar}: #{instance_variable_get(ivar).inspect}"}.join(', ')}>" end |
#to_i ⇒ Object
117 118 119 |
# File 'lib/geoplanet/place.rb', line 117 def to_i self.woeid.to_i end |
#to_s ⇒ Object
113 114 115 |
# File 'lib/geoplanet/place.rb', line 113 def to_s self.name end |