Class: WMATA::Station

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

Overview

Resource class representing a station in the metro system.

Available attribute methods:

  • +code - The code associated with a specific station.

  • +name - The name of the station.

  • lat - The latitude of the station.

  • lon - The longitude of the station.

StationTogether2 - Unused.

Instance Attribute Summary

Attributes inherited from Resource

#attrs

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

endpoint, get_all, #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(code) ⇒ Object

Get a specific station by its code.



24
25
26
27
# File 'lib/resources/station.rb', line 24

def self.get(code)
  url = WMATA.base_url % [service, "JStationInfo", to_query_string("StationCode" => code)]
  new(HTTParty.get(url))
end

.get_on_line(line) ⇒ Object

Get all stations on a given line; argument can be a Line instance, a string line code, or a symbol name (e.g., :red).



18
19
20
21
# File 'lib/resources/station.rb', line 18

def self.get_on_line(line)
  line = Line.symbol_to_line_code(line) if line.is_a?(Symbol)
  get_all("LineCode" => line.to_s)
end

Instance Method Details

#codesObject

Get all possible codes for this station (some stations are in together with another so they are technically identified by two station codes).



31
32
33
# File 'lib/resources/station.rb', line 31

def codes
  [@attrs['Code'], @attrs['StationTogether1'], @attrs['StationTogether2']].compact.delete_if {|c| c == ''}
end

#coordinatesObject Also known as: coords



75
76
77
# File 'lib/resources/station.rb', line 75

def coordinates
  [latitude, longitude]
end

#elevator_incidentsObject

Get all elevator incidents affecting this station.



51
52
53
# File 'lib/resources/station.rb', line 51

def elevator_incidents
  @elevator_incidents ||= ElevatorIncident.get_by_station(self)
end

#latitudeObject



67
68
69
# File 'lib/resources/station.rb', line 67

def latitude
  @attrs['Lat']
end

#line_codesObject

Get the line codes for this station (some stations serve more than one line).



36
37
38
# File 'lib/resources/station.rb', line 36

def line_codes
  [@attrs['LineCode1'], @attrs['LineCode2'], @attrs['LineCode3'], @attrs['LineCode4']].compact.delete_if {|c| c == ''}
end

#linesObject

Get Line instances for the lines serviced by this station.



41
42
43
# File 'lib/resources/station.rb', line 41

def lines
  @lines ||= line_codes.map {|l| Line.get(l)}
end

#longitudeObject



71
72
73
# File 'lib/resources/station.rb', line 71

def longitude
  @attrs['Lon']
end

#path_from(from) ⇒ Object

Build a path from this station to another station identified by its code or as a Station instance.



63
64
65
# File 'lib/resources/station.rb', line 63

def path_from(from)
  WMATA.build_path(from, self)
end

#path_to(to) ⇒ Object

Build a path from this station to another identified by its code or as a Station instance.



57
58
59
# File 'lib/resources/station.rb', line 57

def path_to(to)
  WMATA.build_path(self, to)
end

#predictionsObject

Get train arrival predictions for this station.



46
47
48
# File 'lib/resources/station.rb', line 46

def predictions
  @predictions ||= Prediction.predict_for(self)
end

#to_sObject



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

def to_s
  @attrs['Code']
end