lib/barometer/formats/format.rb in barometer-0.6.7 vs lib/barometer/formats/format.rb in barometer-0.7.0
- old
+ new
@@ -8,20 +8,25 @@
# Some formats require external Web Services to help
# in the converision. (ie :weather_id -> :geocode)
#
class Query::Format
+ @@fixes_file = File.expand_path(
+ File.join(File.dirname(__FILE__), '..', 'translations', 'weather_country_codes.yml'))
+ @@fixes = nil
+
# stubs
#
def self.regex; raise NotImplementedError; end
def self.format; raise NotImplementedError; end
# defaults
#
def self.to(query=nil,country=nil); nil; end
def self.country_code(query=nil); nil; end
def self.convertable_formats; []; end
+ def self.convert_query(text); text; end
# is the query of this format?
#
def self.is?(query=nil)
raise ArgumentError unless query.is_a?(String)
@@ -38,9 +43,22 @@
# is the object a Barometer::Query?
#
def self.is_a_query?(object=nil)
return false unless object
object.is_a?(Barometer::Query)
+ end
+
+ private
+
+ # fix the country code
+ #
+ # weather.com uses non-standard two letter country codes that
+ # hinder the ability to determine the country or fetch geo_data.
+ # correct these "mistakes"
+ #
+ def self._fix_country(country_code)
+ @@fixes ||= YAML.load_file(@@fixes_file)
+ @@fixes[country_code.upcase.to_s] || country_code
end
end
end
\ No newline at end of file