Class: Barometer::Query::Format::Geocode
- Inherits:
-
Barometer::Query::Format
- Object
- Barometer::Query::Format
- Barometer::Query::Format::Geocode
- Defined in:
- lib/barometer/formats/geocode.rb
Overview
Format: Geocode (not to be confused with the WebService geocode)
eg. 123 Elm St, Mystery, Alaska, USA
This class is used to determine if a query is a :geocode, how to convert to :geocode
Class Method Summary collapse
- .convertable_formats ⇒ Object
- .format ⇒ Object
-
.geocode(original_query) ⇒ Object
geocode the query.
- .is?(query = nil) ⇒ Boolean
-
.to(original_query) ⇒ Object
convert to this format, X -> :geocode.
Methods inherited from Barometer::Query::Format
converts?, country_code, is_a_query?, regex
Class Method Details
.convertable_formats ⇒ Object
15 16 17 |
# File 'lib/barometer/formats/geocode.rb', line 15 def self.convertable_formats [:short_zipcode, :zipcode, :coordinates, :weather_id, :icao] end |
.format ⇒ Object
13 |
# File 'lib/barometer/formats/geocode.rb', line 13 def self.format; :geocode; end |
.geocode(original_query) ⇒ Object
geocode the query
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/barometer/formats/geocode.rb', line 36 def self.geocode(original_query) raise ArgumentError unless is_a_query?(original_query) converted_query = Barometer::Query.new #converted_query.geo = _geocode(original_query) converted_query.geo = WebService::Geocode.fetch(original_query) if converted_query.geo converted_query.country_code = converted_query.geo.country_code converted_query.q = converted_query.geo.to_s converted_query.format = format end converted_query end |
.is?(query = nil) ⇒ Boolean
14 |
# File 'lib/barometer/formats/geocode.rb', line 14 def self.is?(query=nil); query.is_a?(String) ? true : false; end |
.to(original_query) ⇒ Object
convert to this format, X -> :geocode
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/barometer/formats/geocode.rb', line 21 def self.to(original_query) raise ArgumentError unless is_a_query?(original_query) unless converts?(original_query) return (original_query.format == format ? original_query.dup : nil) end converted_query = Barometer::Query.new converted_query = (original_query.format == :weather_id ? Query::Format::WeatherID.reverse(original_query) : geocode(original_query)) converted_query end |