Class: WMATA::Line

Inherits:
Resource show all
Defined in:
lib/resources/line.rb

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 - See internal_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

#attrs

Class Method Summary collapse

Instance Method Summary collapse

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_memoizeObject



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

#codeObject

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_stationObject

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_destinationsObject

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_incidentsObject 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.(self)
end

#routeObject 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_stationObject

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_sObject



82
83
84
# File 'lib/resources/line.rb', line 82

def to_s
  code
end