Module: Barometer::Query::Format
- Defined in:
- lib/barometer/query/format.rb,
lib/barometer/query/formats/base.rb,
lib/barometer/query/formats/icao.rb,
lib/barometer/query/formats/woe_id.rb,
lib/barometer/query/formats/geocode.rb,
lib/barometer/query/formats/unknown.rb,
lib/barometer/query/formats/zipcode.rb,
lib/barometer/query/formats/postalcode.rb,
lib/barometer/query/formats/weather_id.rb,
lib/barometer/query/formats/coordinates.rb,
lib/barometer/query/formats/ipv4_address.rb,
lib/barometer/query/formats/short_zipcode.rb,
lib/barometer/query/formats/noaa_station_id.rb
Defined Under Namespace
Classes: Base, Coordinates, Geocode, Icao, Ipv4Address, NoaaStationId, NotFound, Postalcode, ShortZipcode, Unknown, WeatherID, WoeID, Zipcode
Constant Summary
collapse
- @@formats =
[]
Class Method Summary
collapse
Class Method Details
.find(key) ⇒ Object
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/barometer/query/format.rb', line 25
def self.find(key)
@@formats ||= []
format = @@formats.select{|format| format[0] == key.to_sym}
if format && format[0]
format[0][1]
else
raise NotFound
end
end
|
12
13
14
|
# File 'lib/barometer/query/format.rb', line 12
def self.formats
@@formats
end
|
8
9
10
|
# File 'lib/barometer/query/format.rb', line 8
def self.formats=(formats)
@@formats = formats
end
|
.has?(key) ⇒ Boolean
21
22
23
|
# File 'lib/barometer/query/format.rb', line 21
def self.has?(key)
!@@formats.select{|format| format[0] == key.to_sym}.empty?
end
|
.match?(q) ⇒ Boolean
36
37
38
39
40
41
42
43
|
# File 'lib/barometer/query/format.rb', line 36
def self.match?(q)
@@formats.detect do |key, klass|
if klass.is?(q)
yield(key, klass)
true
end
end
end
|
.register(key, format) ⇒ Object
16
17
18
19
|
# File 'lib/barometer/query/format.rb', line 16
def self.register(key, format)
@@formats ||= []
@@formats << [ key.to_sym, format ] unless has?(key)
end
|