module Airports

Constants

VERSION

Public Class Methods

all() click to toggle source
# File lib/airports.rb, line 28
def self.all
  @all ||= parsed_data.values.map do |airport_data|
    airport_from_parsed_data_element(airport_data)
  end
end
find_all_by_city_name(city_name) click to toggle source
# File lib/airports.rb, line 20
def self.find_all_by_city_name(city_name)
  all.select { |airport| airport.city.casecmp(city_name).zero? }
end
find_by_iata_code(iata_code) click to toggle source
# File lib/airports.rb, line 8
def self.find_by_iata_code(iata_code)
  return unless iata_code.length == 3

  all.find { |airport| airport.iata == iata_code }
end
find_by_icao_code(icao_code) click to toggle source
# File lib/airports.rb, line 14
def self.find_by_icao_code(icao_code)
  return unless icao_code.length == 4

  all.find { |airport| airport.icao == icao_code }
end
iata_codes() click to toggle source
# File lib/airports.rb, line 24
def self.iata_codes
  parsed_data.keys
end
parsed_data() click to toggle source
# File lib/airports.rb, line 34
def self.parsed_data
  @parsed_data ||= JSON.parse(data)
end

Private Class Methods

airport_from_parsed_data_element(parsed_data_element) click to toggle source
# File lib/airports.rb, line 38
def self.airport_from_parsed_data_element(parsed_data_element)
  # TODO: Once we're using Ruby 2.5+, use Hash#transform_keys here to symbolize the keys
  transformed_hash = parsed_data_element.transform_keys(&:to_sym)

  Airport.new(**transformed_hash)
end
data() click to toggle source
# File lib/airports.rb, line 46
def self.data
  @data ||= File.read(data_path)
end
data_path() click to toggle source
# File lib/airports.rb, line 51
def self.data_path
  File.expand_path("../data/airports.json", __dir__)
end