Class: WMATA::Line
Overview
A resource class representing a rail line.
Available attribute methods:
-
display_name
- The public name (color) of the line. -
start_station_code
- The code associated with the first station on the line. -
end_station_code
- The code associated with the last station on the line. -
internal_destination1
- Some trains can start/finish their trips not only at the first/last station, but at intermediate stations along the line. -
internal_destination2
- Seeinternal_destination
.
Constant Summary collapse
- SYMBOL_TO_LINES_MAP =
{ :red => "RD", :blue => "BL", :orange => "OR", :green => "GR", :yellow => "YE" }
Instance Attribute Summary
Attributes inherited from Resource
Class Method Summary collapse
-
.get_all(params) ⇒ Object
NOTE: We memoize this since (a) there’s no way to ask for just one line and (b) they’re unlikely to change while we’re doing a request.
- .get_all_without_memoize ⇒ Object
- .symbol_to_line_code(symbol) ⇒ Object
Instance Method Summary collapse
-
#code ⇒ Object
Returns the line’s code (also available as
line_code
). -
#end_station ⇒ Object
Get the last station on this line.
-
#get(code) ⇒ Object
Get a specific line, identified by line code (e.g., “RD”) or a
Symbol
string name (e.g.,:red
). -
#internal_destinations ⇒ Object
Get all internal destinations (some lines “end” or “begin” at more than one station).
-
#rail_incidents ⇒ Object
(also: #incidents)
Get all rail incidents on this line.
-
#route ⇒ Object
(also: #stations)
Get all the stations on this line ordered by the route.
-
#start_station ⇒ Object
Get the first station on this line.
- #to_s ⇒ Object
Methods inherited from Resource
endpoint, #initialize, #method_missing, service, to_query_string
Constructor Details
This class inherits a constructor from WMATA::Resource
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class WMATA::Resource
Class Method Details
.get_all(params) ⇒ Object
NOTE: We memoize this since (a) there’s no way to ask for just one line and (b) they’re unlikely to change while we’re doing a request.
29 30 31 |
# File 'lib/resources/line.rb', line 29 def get_all(params) @lines ||= get_all_without_memoize(params) end |
.get_all_without_memoize ⇒ Object
25 |
# File 'lib/resources/line.rb', line 25 alias_method :get_all_without_memoize, :get_all |
.symbol_to_line_code(symbol) ⇒ Object
33 34 35 |
# File 'lib/resources/line.rb', line 33 def symbol_to_line_code(symbol) SYMBOL_TO_LINES_MAP[symbol] end |
Instance Method Details
#code ⇒ Object
Returns the line’s code (also available as line_code
).
78 79 80 |
# File 'lib/resources/line.rb', line 78 def code @attrs['LineCode'] end |
#end_station ⇒ Object
Get the last station on this line.
44 45 46 |
# File 'lib/resources/line.rb', line 44 def end_station @end_station ||= Station.get(@attrs['EndStationCode']) end |
#get(code) ⇒ Object
Get a specific line, identified by line code (e.g., “RD”) or a Symbol
string name (e.g., :red
).
72 73 74 75 |
# File 'lib/resources/line.rb', line 72 def get(code) code = Line.symbol_to_line_code(code) if code.is_a?(Symbol) get_all.select {|l| l.code == code}.pop end |
#internal_destinations ⇒ Object
Get all internal destinations (some lines “end” or “begin” at more than one station).
50 51 52 53 54 |
# File 'lib/resources/line.rb', line 50 def internal_destinations [@attrs['InternalDestination1'], @attrs['InternalDestination2']].compact.map do |s| Station.get(s) end end |
#rail_incidents ⇒ Object Also known as: incidents
Get all rail incidents on this line.
57 58 59 |
# File 'lib/resources/line.rb', line 57 def rail_incidents @incidents ||= RailIncident.get_by_line(self) end |
#route ⇒ Object Also known as: stations
Get all the stations on this line ordered by the route.
64 65 66 |
# File 'lib/resources/line.rb', line 64 def route Station.get_on_line(code) end |
#start_station ⇒ Object
Get the first station on this line.
39 40 41 |
# File 'lib/resources/line.rb', line 39 def start_station @start_station ||= Station.get(@attrs['StartStationCode']) end |
#to_s ⇒ Object
82 83 84 |
# File 'lib/resources/line.rb', line 82 def to_s code end |