Module: AmtrakStations
- Defined in:
- lib/amtrak_stations.rb,
lib/amtrak_stations/station.rb,
lib/amtrak_stations/version.rb
Defined Under Namespace
Classes: Station
Constant Summary collapse
- VERSION =
"1.0.0".freeze
Class Method Summary collapse
- .all ⇒ Object
- .find_by_station_code(station_code) ⇒ Object
- .parsed_data ⇒ Object
- .station_codes ⇒ Object
Class Method Details
.all ⇒ Object
21 22 23 24 25 26 27 |
# 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) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# 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 ⇒ Object
29 30 31 |
# File 'lib/amtrak_stations.rb', line 29 def self.parsed_data @parsed_data ||= JSON.parse(data) end |
.station_codes ⇒ Object
17 18 19 |
# File 'lib/amtrak_stations.rb', line 17 def self.station_codes parsed_data.keys end |