Module: WMATA

Defined in:
lib/wmata.rb,
lib/resource.rb,
lib/resources/line.rb,
lib/resources/prediction.rb,
lib/resources/path_segment.rb,
lib/resources/rail_incident.rb,
lib/resources/station_entrance.rb,
lib/resources/elevator_incident.rb

Defined Under Namespace

Classes: ElevatorIncident, Line, PathSegment, Prediction, RailIncident, Resource, StationEntrance

Constant Summary collapse

BASE_URL =
"http://api.wmata.com/%s.svc/json/%s?api_key=%s%s"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.api_keyObject

Returns the value of attribute api_key.



20
21
22
# File 'lib/wmata.rb', line 20

def api_key
  @api_key
end

Class Method Details

.base_urlObject

Get the base URL based on the API key given. Used in nearly every method that contacts the remote API.



24
25
26
# File 'lib/wmata.rb', line 24

def base_url
  BASE_URL.dup % ["%s", "%s", @api_key, "%s"]    
end

.build_path(from, to) ⇒ Object

Map a path between two stations, identified by their station codes; returns an array of stations ordered by the path. You can also provide Station instances and get a path between them.

WMATA.build_path("C02", "A01")
# => [#<Station:0x0702aca8>, ...]


110
111
112
# File 'lib/wmata.rb', line 110

def build_path(from, to)
  PathSegment.get_all("FromStationCode" => from, "ToStationCode" => to)
end

.elevator_incidentsObject

Get an array of elevator incidents for all lines; use the elevator_incidents method on Station to get them for a specific station.

WMATA.elevator_incidents.map {|i| i.symptom_code}
# => ["1419", ...]


99
100
101
# File 'lib/wmata.rb', line 99

def elevator_incidents
  ElevatorIncident.get_all
end

.entrances(from = {}) ⇒ Object Also known as: station_entrances, entrances_near

Find entrances near a given latitude and longitude within a given radius (in meters).

If no geolocation information is given, all entrances are returned.

WMATA.entrances(:lat => 28.82083, :lon => 88.9239423, :radius => 2000)
# => [#<StationEntrance:0x0702aca8>, ...]


120
121
122
123
# File 'lib/wmata.rb', line 120

def entrances(from={})
  params = {:lat => 0, :lon => 0, :radius => 500}.merge(from)
  StationEntrance.get_all(params)
end

.linesObject

Get all rail lines.

WMATA.lines.map {|l| l.code}
# => ["RD", "BL", "GR", "OR", "YE"]


33
34
35
# File 'lib/wmata.rb', line 33

def lines
  Line.get_all
end

.predict_for(station = "All") ⇒ Object Also known as: get_predictions

Get station predictions (i.e., train arrival information seen on station terminals) for a specific station; if no station code is provided, it will get predictions for all stations.

predictions = WMATA.predict_for("C02")
# => [#<Prediction:0x1205aee8 ...>, ...]
puts "#{predictions.first.location_name} => #{predictions.first.destination_name}"
# McPherson Square => Metro Center


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

def predict_for(station="All")
  Prediction.predict_for(station)
end

.rail_incidentsObject Also known as: incidents

Get an array of rail incidents for all lines; use the incidents method on Line to get them for a specific line or the same method.

WMATA.rail_incidents.map {|i| i.description}
# => ["Friendship Heights is closed...", ...]


87
88
89
# File 'lib/wmata.rb', line 87

def rail_incidents
  RailIncident.get_all
end

.station(code) ⇒ Object

Get a specific station by code.

WMATA.station("C02")
# => #<Station:0x1205aee8 "McPherson Square">


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

def station(code)
  Station.get(code)
end

.stationsObject

Get all stations.

WMATA.stations.map {|s| s.name }
# => ["McPherson Square", "Metro Center", ...]


42
43
44
# File 'lib/wmata.rb', line 42

def stations
  Station.get_all
end

.stations_on_line(code) ⇒ Object

Get an array of stations on a particular line. Can be called with a line code (e.g., RD) or a symbol for the line name (e.g., :red).

WMATA.stations_on_line(:red)
# => [#<Station:0x0702aca8>, ...]


62
63
64
# File 'lib/wmata.rb', line 62

def stations_on_line(code)
  Station.get_on_line(code)
end