Class: MBTA::HeavyRail::System::Builder
- Inherits:
-
Object
- Object
- MBTA::HeavyRail::System::Builder
- Defined in:
- lib/mbta/heavy_rail/system.rb
Instance Method Summary collapse
-
#initialize ⇒ Builder
constructor
A new instance of Builder.
- #map ⇒ Object
Constructor Details
#initialize ⇒ Builder
Returns a new instance of Builder.
17 18 19 |
# File 'lib/mbta/heavy_rail/system.rb', line 17 def initialize @data = ::CSV.read("../data/RealTimeHeavyRailKeys.csv", { headers: true }) end |
Instance Method Details
#map ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/mbta/heavy_rail/system.rb', line 21 def map data = @data line_names = data.inject(Array.new) {|memo, platform| memo.push(platform['Line']) }.uniq lines = line_names.map{|name| MBTA::HeavyRail::Line.new(name) } lines.each do |line| platforms = data.select {|row| row['Line'] == line.name } station_names = platforms.inject(Array.new) {|memo, platform| memo.push(platform['StationName']) }.uniq line.stations = station_names.map {|name| MBTA::HeavyRail::Station.new(line, name.capitalize) } line.stations.each do |station| data.select{|row| row['StationName'].capitalize == station.name }.each do |row| direction = case row['Direction'] when 'NB' then :northbound when 'SB' then :southbound when 'EB' then :eastbound when 'WB' then :westbound end key = row['PlatformKey'].downcase.to_sym station.platforms.push(MBTA::HeavyRail::Platform.new(station, direction, row['PlatformOrder'], key)) end end end _lines = lines.inject(Hash.new){|lines, line| lines[line.name] = line; lines } map = MBTA::HeavyRail::System::Map.new(_lines) return map end |