Class: Barometer::Query::Format::Coordinates
- Inherits:
-
Barometer::Query::Format
- Object
- Barometer::Query::Format
- Barometer::Query::Format::Coordinates
- Defined in:
- lib/barometer/formats/coordinates.rb
Overview
Format: Coordinates
eg. 123.1234,-123.123
This class is used to determine if a query is a :coordinates and how to convert to :coordinates.
Class Method Summary collapse
- .convertable_formats ⇒ Object
- .format ⇒ Object
- .regex ⇒ Object
-
.to(original_query) ⇒ Object
convert to this format, X -> :coordinates.
Methods inherited from Barometer::Query::Format
converts?, country_code, is?, is_a_query?
Class Method Details
.convertable_formats ⇒ Object
14 15 16 |
# File 'lib/barometer/formats/coordinates.rb', line 14 def self.convertable_formats [:short_zipcode, :zipcode, :postalcode, :weather_id, :coordinates, :icao, :geocode] end |
.format ⇒ Object
12 |
# File 'lib/barometer/formats/coordinates.rb', line 12 def self.format; :coordinates; end |
.regex ⇒ Object
13 |
# File 'lib/barometer/formats/coordinates.rb', line 13 def self.regex; /^[-]?[0-9\.]+[,]{1}[-]?[0-9\.]+$/; end |
.to(original_query) ⇒ Object
convert to this format, X -> :coordinates
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/barometer/formats/coordinates.rb', line 20 def self.to(original_query) raise ArgumentError unless is_a_query?(original_query) # return nil unless converts?(original_query) converted_query = Barometer::Query.new # pre-convert # pre_query = nil if original_query.format == :weather_id unless pre_query = original_query.get_conversion(Query::Format::Geocode.format) pre_query = Query::Format::WeatherID.reverse(original_query) original_query.post_conversion(pre_query) end end # convert & adjust # converted_query = Query::Format::Geocode.geocode(pre_query || original_query) converted_query.q = converted_query.geo.coordinates if converted_query.geo converted_query.format = format converted_query end |