Sha256: 824295c463135ac5a66fdfac7f6a0d473b2772cf376d938f7052bbce3080e36c
Contents?: true
Size: 1.3 KB
Versions: 6
Compression:
Stored size: 1.3 KB
Contents
module Barometer # # 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 Query::Format::Coordinates < Query::Format def self.format; :coordinates; end def self.regex; /^[-]?[0-9\.]+[,]{1}[-]?[0-9\.]+$/; end def self.convertable_formats [:short_zipcode, :zipcode, :postalcode, :weather_id, :coordinates, :icao, :geocode] end # convert to this format, X -> :coordinates # 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 end end
Version data entries
6 entries across 6 versions & 2 rubygems