module AmtrakStations
Constants
- VERSION
Public Class Methods
all()
click to toggle source
# File lib/amtrak_stations.rb, line 21 def self.all @all ||= parsed_data.map do |_station_code, station_data| Station.new( station_data.each_with_object({}) { |(k, v), h| h[k.to_sym] = v } ) end end
find_by_station_code(station_code)
click to toggle source
# File lib/amtrak_stations.rb, line 6 def self.find_by_station_code(station_code) return unless station_code.length == 3 station_data = parsed_data.fetch(station_code, nil) return unless station_data Station.new( station_data.each_with_object({}) { |(k, v), h| h[k.to_sym] = v } ) end
parsed_data()
click to toggle source
# File lib/amtrak_stations.rb, line 29 def self.parsed_data @parsed_data ||= JSON.parse(data) end
station_codes()
click to toggle source
# File lib/amtrak_stations.rb, line 17 def self.station_codes parsed_data.keys end
Private Class Methods
data()
click to toggle source
# File lib/amtrak_stations.rb, line 33 def self.data @data || File.read(data_path) end
data_path()
click to toggle source
# File lib/amtrak_stations.rb, line 38 def self.data_path File.expand_path("../data/stations.json", __dir__) end