Sha256: 22cc634292e83eda269cd060793d19b5920863787a3748ec275db5db4d4204cb
Contents?: true
Size: 1.76 KB
Versions: 1
Compression:
Stored size: 1.76 KB
Contents
require 'mbta/heavy_rail/line' require 'mbta/heavy_rail/station' require 'mbta/heavy_rail/platform' module MBTA module HeavyRail module System class Map attr_reader :lines def initialize(lines = {}) @lines = lines end end class Builder def initialize @data = ::CSV.read("../data/RealTimeHeavyRailKeys.csv", { headers: true }) end 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 end MAP = Builder.new.map end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mbta-0.1.4 | lib/mbta/heavy_rail/system.rb |