Class: Barometer::Query::Format
- Inherits:
-
Object
- Object
- Barometer::Query::Format
- Defined in:
- lib/barometer/formats/format.rb
Overview
Base Format Class
Fromats are used to determine if a query is of a certain format, how to convert to and from that format and what the country_code is for that format (if possible). Some formats require external Web Services to help in the converision. (ie :weather_id -> :geocode)
Direct Known Subclasses
Coordinates, Geocode, Postalcode, ShortZipcode, WeatherID, WoeID, Zipcode, Query::Format::Icao
Defined Under Namespace
Classes: Coordinates, Geocode, Icao, Postalcode, ShortZipcode, WeatherID, WoeID, Zipcode
Constant Summary collapse
- @@fixes_file =
File.( File.join(File.dirname(__FILE__), '..', 'translations', 'weather_country_codes.yml'))
- @@fixes =
nil
Class Method Summary collapse
- .convert_query(text) ⇒ Object
- .convertable_formats ⇒ Object
-
.converts?(query = nil) ⇒ Boolean
does the format support conversion from the given query?.
- .country_code(query = nil) ⇒ Object
- .format ⇒ Object
-
.is?(query = nil) ⇒ Boolean
is the query of this format?.
-
.is_a_query?(object = nil) ⇒ Boolean
is the object a Barometer::Query?.
-
.regex ⇒ Object
stubs.
-
.to(query = nil, country = nil) ⇒ Object
defaults.
Class Method Details
.convert_query(text) ⇒ Object
27 |
# File 'lib/barometer/formats/format.rb', line 27 def self.convert_query(text); text; end |
.convertable_formats ⇒ Object
26 |
# File 'lib/barometer/formats/format.rb', line 26 def self.convertable_formats; []; end |
.converts?(query = nil) ⇒ Boolean
does the format support conversion from the given query?
38 39 40 41 |
# File 'lib/barometer/formats/format.rb', line 38 def self.converts?(query=nil) return false unless is_a_query?(query) self.convertable_formats.include?(query.format) end |
.country_code(query = nil) ⇒ Object
25 |
# File 'lib/barometer/formats/format.rb', line 25 def self.country_code(query=nil); nil; end |
.format ⇒ Object
20 |
# File 'lib/barometer/formats/format.rb', line 20 def self.format; raise NotImplementedError; end |
.is?(query = nil) ⇒ Boolean
is the query of this format?
31 32 33 34 |
# File 'lib/barometer/formats/format.rb', line 31 def self.is?(query=nil) raise ArgumentError unless query.is_a?(String) return !(query =~ self.regex).nil? end |
.is_a_query?(object = nil) ⇒ Boolean
is the object a Barometer::Query?
45 46 47 48 |
# File 'lib/barometer/formats/format.rb', line 45 def self.is_a_query?(object=nil) return false unless object object.is_a?(Barometer::Query) end |
.regex ⇒ Object
stubs
19 |
# File 'lib/barometer/formats/format.rb', line 19 def self.regex; raise NotImplementedError; end |
.to(query = nil, country = nil) ⇒ Object
defaults
24 |
# File 'lib/barometer/formats/format.rb', line 24 def self.to(query=nil,country=nil); nil; end |