Class: MQReader::MQGeocode
- Inherits:
-
Object
- Object
- MQReader::MQGeocode
- Defined in:
- lib/mq_reader/mq_reader.rb
Overview
Class to handle the response from the mapquest api
Provides methods to get every value from the geocoded address.
Instance Attribute Summary collapse
-
#city ⇒ Object
readonly
Returns the value of attribute city.
-
#country ⇒ Object
readonly
Returns the value of attribute country.
-
#county ⇒ Object
readonly
Returns the value of attribute county.
-
#lat ⇒ Object
readonly
Returns the value of attribute lat.
-
#lng ⇒ Object
readonly
Returns the value of attribute lng.
-
#raw_geocode ⇒ Object
readonly
Returns the value of attribute raw_geocode.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#street ⇒ Object
readonly
Returns the value of attribute street.
-
#zip ⇒ Object
readonly
Returns the value of attribute zip.
Instance Method Summary collapse
- #address_found? ⇒ Boolean
-
#initialize(json_geocode) ⇒ MQGeocode
constructor
A new instance of MQGeocode.
Constructor Details
#initialize(json_geocode) ⇒ MQGeocode
Returns a new instance of MQGeocode.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/mq_reader/mq_reader.rb', line 109 def initialize(json_geocode) @raw_geocode = JSON.parse(json_geocode) raise StandardError, "The request raised an error: #{@raw_geocode['info']['messages']}" if @raw_geocode['info']['statuscode'] != 0 return if @raw_geocode['results'].first['locations'].empty? @lng,@lat = lat_lng_values @street = value('street') @city = value('adminArea5') @county = value('adminArea4') @state = value('adminArea3') @country = value('adminArea1') @zip = value('postalCode') @type = value('type') @geocode_quality = value('geocodeQuality') @side_of_street = value('sideOfStreet') end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_sym, *arguments, &block) ⇒ Object (private)
Use method_missing to define accesors for any response attributes that might not be listed in #initialize This accesors are rubyish(underscore notation).
144 145 146 147 |
# File 'lib/mq_reader/mq_reader.rb', line 144 def method_missing(method_sym, *arguments, &block) result = send(:value, BaseClass.camelize_string(method_sym.to_s)) result.empty? ? super : result end |
Instance Attribute Details
#city ⇒ Object (readonly)
Returns the value of attribute city.
107 108 109 |
# File 'lib/mq_reader/mq_reader.rb', line 107 def city @city end |
#country ⇒ Object (readonly)
Returns the value of attribute country.
107 108 109 |
# File 'lib/mq_reader/mq_reader.rb', line 107 def country @country end |
#county ⇒ Object (readonly)
Returns the value of attribute county.
107 108 109 |
# File 'lib/mq_reader/mq_reader.rb', line 107 def county @county end |
#lat ⇒ Object (readonly)
Returns the value of attribute lat.
107 108 109 |
# File 'lib/mq_reader/mq_reader.rb', line 107 def lat @lat end |
#lng ⇒ Object (readonly)
Returns the value of attribute lng.
107 108 109 |
# File 'lib/mq_reader/mq_reader.rb', line 107 def lng @lng end |
#raw_geocode ⇒ Object (readonly)
Returns the value of attribute raw_geocode.
107 108 109 |
# File 'lib/mq_reader/mq_reader.rb', line 107 def raw_geocode @raw_geocode end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
107 108 109 |
# File 'lib/mq_reader/mq_reader.rb', line 107 def state @state end |
#street ⇒ Object (readonly)
Returns the value of attribute street.
107 108 109 |
# File 'lib/mq_reader/mq_reader.rb', line 107 def street @street end |
#zip ⇒ Object (readonly)
Returns the value of attribute zip.
107 108 109 |
# File 'lib/mq_reader/mq_reader.rb', line 107 def zip @zip end |
Instance Method Details
#address_found? ⇒ Boolean
125 126 127 |
# File 'lib/mq_reader/mq_reader.rb', line 125 def address_found? @raw_geocode['results'].first['locations'].any? end |