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, Zipcode

Class Method Summary collapse

Class Method Details

.convertable_formatsObject



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

def self.convertable_formats; []; end

.converts?(query = nil) ⇒ Boolean

does the format support conversion from the given query?

Returns:

  • (Boolean)


33
34
35
36
# File 'lib/barometer/formats/format.rb', line 33

def self.converts?(query=nil)
  return false unless is_a_query?(query)
  self.convertable_formats.include?(query.format)
end

.country_code(query = nil) ⇒ Object



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

def self.country_code(query=nil); nil; end

.formatObject

Raises:

  • (NotImplementedError)


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

def self.format; raise NotImplementedError; end

.is?(query = nil) ⇒ Boolean

is the query of this format?

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


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

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)


40
41
42
43
# File 'lib/barometer/formats/format.rb', line 40

def self.is_a_query?(object=nil)
  return false unless object
  object.is_a?(Barometer::Query)
end

.regexObject

stubs

Raises:

  • (NotImplementedError)


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

def self.regex; raise NotImplementedError; end

.to(query = nil, country = nil) ⇒ Object

defaults



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

def self.to(query=nil,country=nil); nil; end