Class: Bing::Location
Overview
Responsible for obtaining a location based off of data passed in. Most common method is to do:
Bing::Location.find :query => ‘123 Address City State’
Constant Summary collapse
- PATH =
Path to location resource.
'/REST/v1/Locations'
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#bounding_box ⇒ Object
readonly
Returns the value of attribute bounding_box.
-
#canonical_description ⇒ Object
readonly
Returns the value of attribute canonical_description.
-
#city ⇒ Object
readonly
Returns the value of attribute city.
-
#confidence ⇒ Object
readonly
Returns the value of attribute confidence.
-
#coordinates ⇒ Object
readonly
Returns the value of attribute coordinates.
-
#country ⇒ Object
readonly
Returns the value of attribute country.
-
#entity_type ⇒ Object
readonly
Returns the value of attribute entity_type.
-
#full_name ⇒ Object
readonly
Returns the value of attribute full_name.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#zip ⇒ Object
readonly
Returns the value of attribute zip.
Class Method Summary collapse
-
.find(opts) ⇒ Object
Will find locations based off of
queryand return an array of Bing::Location objects.
Instance Method Summary collapse
-
#initialize(resource) ⇒ Location
constructor
A new instance of Location.
Constructor Details
#initialize(resource) ⇒ Location
Returns a new instance of Location.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/bing/location.rb', line 44 def initialize resource raise LocationResourceMissing if resource.blank? @confidence = resource['confidence'] @entity_type = resource['entityType'] @full_name = resource['name'] if resource['address'] then @address = resource['address']['addressLine'] @city = resource['address']['locality'] @country = resource['address']['countryRegion'] @state = resource['address']['adminDistrict'] @zip = resource['address']['postalCode'] end if resource['bbox'] then @bounding_box = bbox resource['bbox'] end if resource['point'] && resource['point']['coordinates'] then @coordinates = resource['point']['coordinates'] end end |
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address.
32 33 34 |
# File 'lib/bing/location.rb', line 32 def address @address end |
#bounding_box ⇒ Object (readonly)
Returns the value of attribute bounding_box.
33 34 35 |
# File 'lib/bing/location.rb', line 33 def bounding_box @bounding_box end |
#canonical_description ⇒ Object (readonly)
Returns the value of attribute canonical_description.
34 35 36 |
# File 'lib/bing/location.rb', line 34 def canonical_description @canonical_description end |
#city ⇒ Object (readonly)
Returns the value of attribute city.
36 37 38 |
# File 'lib/bing/location.rb', line 36 def city @city end |
#confidence ⇒ Object (readonly)
Returns the value of attribute confidence.
37 38 39 |
# File 'lib/bing/location.rb', line 37 def confidence @confidence end |
#coordinates ⇒ Object (readonly)
Returns the value of attribute coordinates.
35 36 37 |
# File 'lib/bing/location.rb', line 35 def coordinates @coordinates end |
#country ⇒ Object (readonly)
Returns the value of attribute country.
38 39 40 |
# File 'lib/bing/location.rb', line 38 def country @country end |
#entity_type ⇒ Object (readonly)
Returns the value of attribute entity_type.
39 40 41 |
# File 'lib/bing/location.rb', line 39 def entity_type @entity_type end |
#full_name ⇒ Object (readonly)
Returns the value of attribute full_name.
40 41 42 |
# File 'lib/bing/location.rb', line 40 def full_name @full_name end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
41 42 43 |
# File 'lib/bing/location.rb', line 41 def state @state end |
#zip ⇒ Object (readonly)
Returns the value of attribute zip.
42 43 44 |
# File 'lib/bing/location.rb', line 42 def zip @zip end |
Class Method Details
.find(opts) ⇒ Object
Will find locations based off of query and return an array of Bing::Location objects.
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/bing/location.rb', line 20 def self.find opts uri = Bing.config[:map_uri].merge( "#{PATH}?key=#{Bing.config[:api_key]}&#{opts.to_param}" ) body = JSON.parse get(uri).body body['resourceSets'].first['resources'].map do |resource| new resource end.compact end |