Class: Barometer::Query::Format::Icao

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

Overview

ICAO (International Civil Aviation Organization) eg. KLAX (Los Angeles Airport)

Constant Summary collapse

@@codes_file =
File.expand_path(
File.join(File.dirname(__FILE__), 'translations', 'icao_country_codes.yml'))
@@codes =
nil

Class Method Summary collapse

Methods inherited from Base

convert_query, is?

Class Method Details

.geo(query) ⇒ Object

in some cases the first letter can designate the country



22
23
24
25
26
27
28
29
30
31
# File 'lib/barometer/query/formats/icao.rb', line 22

def self.geo(query)
  return unless query && query.is_a?(String)
  $:.unshift(File.dirname(__FILE__))
  @@codes ||= YAML.load_file(@@codes_file)
  return unless @@codes && @@codes['one_letter'] && @@codes['two_letter']
  country_code = @@codes['one_letter'][query[0..0].upcase.to_s] ||
    @@codes['two_letter'][query[0..1].upcase.to_s] || nil

  {country_code: country_code}
end

.regexObject

call any 3-4 letter query, :icao … obviously this will have a lot of false positives. So far this isn’t an issue as all weather services that take :icao (which is just one, :wunderground) also take what this would have been if it was not called :icao.



18
# File 'lib/barometer/query/formats/icao.rb', line 18

def self.regex; /^[A-Za-z]{3,4}$/; end