class Metrorail::Line
A class representing a line in the Metrorail
system.
Attributes
id[R]
name[R]
stations[R]
Public Class Methods
all(force=false)
click to toggle source
# File lib/metrorail.rb, line 123 def self.all(force=false) if @@lines.size > 0 return @@lines else lines_request = Metrorail::make_request("Rail", "jLines")["Lines"] lines = [] lines_request.each do |line| new_line = Line.new(line["LineCode"], line["DisplayName"]) stations = Metrorail::make_request("Rail", "jPath", {fromStationCode: line["StartStationCode"], toStationCode: line["EndStationCode"]})["Path"] stations.each do |station| new_line.add_station(Metrorail::Station.find_by_id(station["StationCode"])) end lines << new_line end return lines end end
find_by_id(id)
click to toggle source
# File lib/metrorail.rb, line 141 def self.find_by_id(id) self.update_cache_if_needed matching = self.all.select { |line| line.id == id } if matching.size > 0 matching[0] else nil end end
new(id, name, stations=[])
click to toggle source
# File lib/metrorail.rb, line 113 def initialize(id, name, stations=[]) @id = id @name = name @stations = [] end
update_cache()
click to toggle source
# File lib/metrorail.rb, line 151 def self.update_cache @@lines = self.all(true) end
update_cache_if_needed()
click to toggle source
# File lib/metrorail.rb, line 155 def self.update_cache_if_needed if @@lines.size == 0 self.update_cache end end
Public Instance Methods
add_station(station)
click to toggle source
# File lib/metrorail.rb, line 119 def add_station(station) @stations << station end