Class: Barometer::Query::Format::WeatherID

Inherits:
Base
  • Object
show all
Defined in:
lib/barometer/query/formats/weather_id.rb

Overview

Weather ID (specific to weather.com) eg. USGA0028

Constant Summary collapse

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

Class Method Summary collapse

Methods inherited from Base

convert_query, is?

Class Method Details

._fix_country(country_code) ⇒ Object

weather.com uses non-standard two letter country codes that hinder the ability to determine the country or fetch geo_data. correct these “mistakes”



27
28
29
30
# File 'lib/barometer/query/formats/weather_id.rb', line 27

def self._fix_country(country_code)
  @@fixes ||= YAML.load_file(@@fixes_file)
  @@fixes[country_code.upcase.to_s] || country_code
end

.geo(query) ⇒ Object



15
16
17
18
19
# File 'lib/barometer/query/formats/weather_id.rb', line 15

def self.geo(query)
  if query && query.size >= 2
    { country_code: _fix_country(query[0..1]) }
  end
end

.regexObject



13
# File 'lib/barometer/query/formats/weather_id.rb', line 13

def self.regex; /(^[A-Za-z]{4}[0-9]{4}$)/; end