Class: Barometer::Query::Format

Inherits:
Object
  • Object
show all
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)

Defined Under Namespace

Classes: Coordinates, Geocode, Icao, Postalcode, ShortZipcode, WeatherID, WoeID, Zipcode

Constant Summary collapse

@@fixes_file =
File.expand_path(
File.join(File.dirname(__FILE__), '..', 'translations', 'weather_country_codes.yml'))
@@fixes =
nil

Class Method Summary collapse

Class Method Details

.convert_query(text) ⇒ Object



27
# File 'lib/barometer/formats/format.rb', line 27

def self.convert_query(text); text; end

.convertable_formatsObject



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?

Returns:

  • (Boolean)


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

.formatObject

Raises:

  • (NotImplementedError)


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?

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


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?

Returns:

  • (Boolean)


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

.regexObject

stubs

Raises:

  • (NotImplementedError)


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