wmata 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +33 -1
- data/VERSION +1 -1
- data/lib/resources/elevator_incident.rb +25 -0
- data/lib/resources/line.rb +33 -1
- data/lib/resources/path_segment.rb +19 -0
- data/lib/resources/prediction.rb +32 -1
- data/lib/resources/rail_incident.rb +30 -1
- data/lib/resources/station.rb +46 -9
- data/lib/resources/station_entrance.rb +26 -0
- data/lib/wmata.rb +61 -1
- data/wmata.gemspec +75 -0
- metadata +4 -3
data/README.rdoc
CHANGED
@@ -1,6 +1,38 @@
|
|
1
1
|
= wmata
|
2
2
|
|
3
|
-
|
3
|
+
Jeremy McAnally - Intridea
|
4
|
+
|
5
|
+
A nice little gem for accessing the WMATA data API (http://developer.wmata.com).
|
6
|
+
|
7
|
+
== Installing / Getting Started
|
8
|
+
|
9
|
+
First, install the gem...
|
10
|
+
|
11
|
+
gem install wmata
|
12
|
+
|
13
|
+
...or use your Git clone. It's up to you. :)
|
14
|
+
|
15
|
+
Next, mosey on over to http://developer.wmata.com and get yourself a developer account. Create an application (it can just be named "test" or whatever for now) and get your API key. You'll need to provide your API key for any API work you'll be doing.
|
16
|
+
|
17
|
+
To get started using the gem, require it (of course), and then set your API key:
|
18
|
+
|
19
|
+
WMATA.api_key = "ab7bce7ba8e08ccca9ce80ab890eb8a9dd"
|
20
|
+
|
21
|
+
Now you're ready to rock and roll!
|
22
|
+
|
23
|
+
== Usage
|
24
|
+
|
25
|
+
The gem's functionality is primarily oriented around the +WMATA+ module. For example, to get all the rail lines available, you'd do this:
|
26
|
+
|
27
|
+
WMATA.lines
|
28
|
+
|
29
|
+
This will give you an array of +Line+ objects to manipulate. So, you could do something like this:
|
30
|
+
|
31
|
+
WMATA.lines.first.incidents
|
32
|
+
|
33
|
+
This code would give you an array of +Incident+ objects that you can manipulate. Essentially, its usage boils down to a simple maxim: most of the fetching logic should be accessed through the +WMATA+ module or the domain objects returned from methods called on methods called on +WMATA+. You can call the fetching logic directly (e.g., +Line.get_all+), but it's smarter to use the public API.
|
34
|
+
|
35
|
+
For detailed information about what methods are available, see the documentation for +WMATA+ and each individual resource class.
|
4
36
|
|
5
37
|
== Note on Patches/Pull Requests
|
6
38
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -1,23 +1,48 @@
|
|
1
1
|
module WMATA
|
2
|
+
# A class representing service incidents in elevators (e.g., an elevator is busted
|
3
|
+
# going between the two floors of the station).
|
4
|
+
#
|
5
|
+
# Available attribute methods:
|
6
|
+
#
|
7
|
+
# * +display_order+ - Display priority
|
8
|
+
# * +date_out_of_service+ - Date when elevator/escalator was switched off.
|
9
|
+
# * +date_updated+ - Time when the information was last received.
|
10
|
+
# * +location_description+ - Location of elevator/escalator.
|
11
|
+
# * +station_code+ - Code of the station affected by the escalator/elevator incident.
|
12
|
+
# * +station_name+ - Name of the station affected by the escalator/elevator incident.
|
13
|
+
# * +symptom_code+ - ID of the reason why elevator/escalator was switched off.
|
14
|
+
# * +symptom_description+ - Information why elevator/escalator was switched off.
|
15
|
+
# * +time_out_of_service+ - Number of minutes the elevator has been out of service until last update of data.
|
16
|
+
# * +unit_name+ - ID of the affected elevator/escalator.
|
17
|
+
# * +unit_status+ - Can be "C" or "O": O means Out of service (has open issues) and C means Operational (open issues were closed).
|
18
|
+
# * +unit_type+ - "ESCALATOR" or "ELEVATOR"
|
19
|
+
#
|
2
20
|
class ElevatorIncident < Resource
|
3
21
|
service "Incidents"
|
4
22
|
endpoint "ElevatorIncidents"
|
5
23
|
|
24
|
+
# Get the incidents by station; provide either a +Station+ instance
|
25
|
+
# or a station code as the argument.
|
6
26
|
def self.get_by_station(affected_station)
|
7
27
|
@incidents ||= get_all
|
8
28
|
@incidents.select {|i| i.station_code == affected_station.to_s }.pop
|
9
29
|
end
|
10
30
|
|
31
|
+
# Get the station affected by the problem.
|
11
32
|
def affected_station
|
12
33
|
Station.get(@attrs['StationCode'])
|
13
34
|
end
|
14
35
|
|
15
36
|
alias_method :station, :affected_station
|
16
37
|
|
38
|
+
# Get a +Time+ object representing the time the elevator went out of
|
39
|
+
# service.
|
17
40
|
def date_out_of_service
|
18
41
|
Time.parse(@attrs['DateOutOfServ'])
|
19
42
|
end
|
20
43
|
|
44
|
+
# Get a +Time+ object representing the last time this API data entry
|
45
|
+
# was updated.
|
21
46
|
def date_updated
|
22
47
|
Time.parse(@attrs['DateUpdated'])
|
23
48
|
end
|
data/lib/resources/line.rb
CHANGED
@@ -1,48 +1,80 @@
|
|
1
1
|
module WMATA
|
2
|
+
# A resource class representing a rail line.
|
3
|
+
#
|
4
|
+
# Available attribute methods:
|
5
|
+
#
|
6
|
+
# * +display_name+ - The public name (color) of the line.
|
7
|
+
# * +start_station_code+ - The code associated with the first station on the line.
|
8
|
+
# * +end_station_code+ - The code associated with the last station on the line.
|
9
|
+
# * +internal_destination1+ - Some trains can start/finish their trips not only at the first/last station, but at intermediate stations along the line.
|
10
|
+
# * +internal_destination2+ - See +internal_destination+.
|
11
|
+
#
|
2
12
|
class Line < Resource
|
3
13
|
service "Rail"
|
4
14
|
endpoint "JLines"
|
5
15
|
|
16
|
+
SYMBOL_TO_LINES_MAP = {
|
17
|
+
:red => "RD",
|
18
|
+
:blue => "BL",
|
19
|
+
:orange => "OR",
|
20
|
+
:green => "GR",
|
21
|
+
:yellow => "YE"
|
22
|
+
}
|
23
|
+
|
6
24
|
class <<self
|
7
25
|
alias_method :get_all_without_memoize, :get_all
|
8
26
|
|
9
|
-
#
|
27
|
+
# NOTE: We memoize this since (a) there's no way to ask for just one line and
|
10
28
|
# (b) they're unlikely to change while we're doing a request.
|
11
29
|
def get_all(params)
|
12
30
|
@lines ||= get_all_without_memoize(params)
|
13
31
|
end
|
32
|
+
|
33
|
+
def symbol_to_line_code(symbol)
|
34
|
+
SYMBOL_TO_LINES_MAP[symbol]
|
35
|
+
end
|
14
36
|
end
|
15
37
|
|
38
|
+
# Get the first station on this line.
|
16
39
|
def start_station
|
17
40
|
@start_station ||= Station.get(@attrs['StartStationCode'])
|
18
41
|
end
|
19
42
|
|
43
|
+
# Get the last station on this line.
|
20
44
|
def end_station
|
21
45
|
@end_station ||= Station.get(@attrs['EndStationCode'])
|
22
46
|
end
|
23
47
|
|
48
|
+
# Get all internal destinations (some lines "end" or "begin" at more than
|
49
|
+
# one station).
|
24
50
|
def internal_destinations
|
25
51
|
[@attrs['InternalDestination1'], @attrs['InternalDestination2']].compact.map do |s|
|
26
52
|
Station.get(s)
|
27
53
|
end
|
28
54
|
end
|
29
55
|
|
56
|
+
# Get all rail incidents on this line.
|
30
57
|
def rail_incidents
|
31
58
|
@incidents ||= RailIncident.get_by_line(self)
|
32
59
|
end
|
33
60
|
|
34
61
|
alias_method :incidents, :rail_incidents
|
35
62
|
|
63
|
+
# Get all the stations on this line ordered by the route.
|
36
64
|
def route
|
37
65
|
Station.get_on_line(code)
|
38
66
|
end
|
39
67
|
|
40
68
|
alias_method :stations, :route
|
41
69
|
|
70
|
+
# Get a specific line, identified by line code (e.g., "RD") or a +Symbol+
|
71
|
+
# string name (e.g., +:red+).
|
42
72
|
def get(code)
|
73
|
+
code = Line.symbol_to_line_code(code) if code.is_a?(Symbol)
|
43
74
|
get_all.select {|l| l.code == code}.pop
|
44
75
|
end
|
45
76
|
|
77
|
+
# Returns the line's code (also available as +line_code+).
|
46
78
|
def code
|
47
79
|
@attrs['LineCode']
|
48
80
|
end
|
@@ -1,18 +1,37 @@
|
|
1
1
|
module WMATA
|
2
|
+
# A resource class representing a segment in a path between two stations.
|
3
|
+
#
|
4
|
+
# Available attribute methods:
|
5
|
+
#
|
6
|
+
# * +station_code+ - The ID code for an individual station.
|
7
|
+
# * +station_name+ - The name of the Station.
|
8
|
+
# * +line_code+ - The ID (color) of the Line associated with the path.
|
9
|
+
# * +seq_num+ - The sequence of the station in the path.
|
10
|
+
# * +distance_to_previous+ - Distance in feet from the previous station in the path.
|
11
|
+
#
|
2
12
|
class PathSegment < Resource
|
3
13
|
service "Rail"
|
4
14
|
endpoint "JPath"
|
5
15
|
|
16
|
+
# Return the +Station+ instance representing the station on
|
17
|
+
# this segment of the path.
|
6
18
|
def station
|
7
19
|
@station ||= Station.get(@attrs['StationCode'])
|
8
20
|
end
|
9
21
|
|
22
|
+
# Returns the +Line+ instance for the line this segment falls on.
|
10
23
|
def line
|
11
24
|
@line ||= Line.get(@attrs['LineCode'])
|
12
25
|
end
|
13
26
|
|
27
|
+
# The position this +PathSegment+ is in the overall path.
|
14
28
|
def index
|
15
29
|
@attrs['SeqNum']
|
16
30
|
end
|
31
|
+
|
32
|
+
# The distance to the previous station in the path.
|
33
|
+
def distance_to_previous
|
34
|
+
@attrs['DistanceToPrev']
|
35
|
+
end
|
17
36
|
end
|
18
37
|
end
|
data/lib/resources/prediction.rb
CHANGED
@@ -1,28 +1,59 @@
|
|
1
1
|
module WMATA
|
2
|
+
# A resource class representing train arrival prediction information.
|
3
|
+
#
|
4
|
+
# Available attribute methods:
|
5
|
+
#
|
6
|
+
# * +car+ - Number of cars in a particular train (usually 6 or 8).
|
7
|
+
# * +destination_code+ - The ID of destination station.
|
8
|
+
# * +destination_name+ - The name of destination station.
|
9
|
+
# * +group+ - Track number (1 or 2).
|
10
|
+
# * +line+ - ID of the metro line.
|
11
|
+
# * +location_code+ - ID of the station where the train is arriving.
|
12
|
+
# * +location_name+ - The name of the station where the train is arriving.
|
13
|
+
# * +arrival_status+ - The minutes to train arrival. Can be +:boarding+, +:arrived+, or positive number.
|
14
|
+
#
|
2
15
|
class Prediction < Resource
|
3
16
|
service "StationPrediction"
|
4
17
|
|
18
|
+
# Get train arrival prediction information for a given station; can
|
19
|
+
# be a station code as a string or a +Station+ instance.
|
5
20
|
def self.predict_for(station_code)
|
6
|
-
url = WMATA.base_url % [service, "GetPrediction/#{station_code}", ""]
|
21
|
+
url = WMATA.base_url % [service, "GetPrediction/#{station_code.to_s}", ""]
|
7
22
|
HTTParty.get(url).first.last.map {|values| new(values) }
|
8
23
|
end
|
9
24
|
|
25
|
+
# Get the arriving station this prediction applies to.
|
10
26
|
def location
|
11
27
|
@location ||= Station.get(@attrs['LocationCode'])
|
12
28
|
end
|
13
29
|
|
14
30
|
alias_method :station, :location
|
15
31
|
|
32
|
+
# Get the destination of the train for this prediction.
|
16
33
|
def destination
|
17
34
|
@destination ||= Station.get(@attrs['DestinationCode'])
|
18
35
|
end
|
19
36
|
|
37
|
+
# Get the line code the line this prediction's station is on.
|
20
38
|
def line_code
|
21
39
|
@attrs['Line']
|
22
40
|
end
|
23
41
|
|
42
|
+
# Get the +Line+ instance for this prediction's station's line.
|
24
43
|
def line
|
25
44
|
@line ||= Line.get(@attrs['Line'])
|
26
45
|
end
|
46
|
+
|
47
|
+
# Get the arrival status of the train. Can be +:boarding+, +:arrived+, or
|
48
|
+
# the number of minutes until the train will arrive.
|
49
|
+
def arrival_status
|
50
|
+
if @attrs['Min'] == "BRD"
|
51
|
+
:boarding
|
52
|
+
elsif @attrs['Min'] == "ARR"
|
53
|
+
:arrived
|
54
|
+
else
|
55
|
+
@attrs['Min'].to_i
|
56
|
+
end
|
57
|
+
end
|
27
58
|
end
|
28
59
|
end
|
@@ -1,23 +1,52 @@
|
|
1
1
|
module WMATA
|
2
|
+
# A resource class representing a rail incident (e.g., garbage on the rails delaying a train).
|
3
|
+
#
|
4
|
+
# Available attribute methods:
|
5
|
+
#
|
6
|
+
# * +incident_id+ - ID of the nicident
|
7
|
+
# * +incident_type+ - Type of the nicident
|
8
|
+
# * +date_updated+ - Date and time where information was updated.
|
9
|
+
# * +delay_severity+ - Severity of delay (if any). Can be +:minor+, +:major+, or +:medium+.
|
10
|
+
# * +description+ - Description what happened.
|
11
|
+
# * +emergency_text+ - Some text for emergency (if any).
|
12
|
+
# * +start_location_full_name+ - Station where delay starts.
|
13
|
+
# * +end_location_full_name+ - Station where delay ends.
|
14
|
+
# * +passenger_delay+ - Delay in minutes.
|
15
|
+
#
|
2
16
|
class RailIncident < Resource
|
3
17
|
service "Incidents"
|
4
18
|
endpoint "Incidents"
|
5
19
|
|
20
|
+
# Get all rail incidents by the line; can be a line code string or
|
21
|
+
# a +Line+ instance.
|
6
22
|
def self.get_by_line(line)
|
7
23
|
@incidents ||= get_all
|
8
24
|
@incidents.select {|i| i.line_codes_affected.include?(line.to_s)}
|
9
25
|
end
|
10
26
|
|
27
|
+
# Get a +Time+ object representing the last time this API data entry
|
28
|
+
# was updated.
|
11
29
|
def date_updated
|
12
30
|
Time.parse(@attrs['DateUpdated'])
|
13
31
|
end
|
14
32
|
|
33
|
+
# Get an array of the line codes affected by this incident.
|
15
34
|
def line_codes_affected
|
16
35
|
@attrs['LinesAffected'].split(";").reject {|s| s.empty? || s.nil?}
|
17
36
|
end
|
18
37
|
|
38
|
+
# Get +Line+ instances for the lines affected by this incident.
|
19
39
|
def lines_affected
|
20
|
-
@lines_affected = line_codes_affected.map {|l| Line.get(l)}
|
40
|
+
@lines_affected = line_codes_affected.map {|l| Line.get(l.strip)}
|
41
|
+
end
|
42
|
+
|
43
|
+
# ID of the incident.
|
44
|
+
def incident_id
|
45
|
+
@attrs['IncidentID']
|
46
|
+
end
|
47
|
+
|
48
|
+
def delay_severity
|
49
|
+
@attrs['DelaySeverity'].to_s.downcase.to_sym
|
21
50
|
end
|
22
51
|
end
|
23
52
|
end
|
data/lib/resources/station.rb
CHANGED
@@ -1,46 +1,83 @@
|
|
1
1
|
module WMATA
|
2
|
+
# Resource class representing a station in the metro system.
|
3
|
+
#
|
4
|
+
# Available attribute methods:
|
5
|
+
#
|
6
|
+
# * +code - The code associated with a specific station.
|
7
|
+
# * +name - The name of the station.
|
8
|
+
# * +lat+ - The latitude of the station.
|
9
|
+
# * +lon+ - The longitude of the station.
|
10
|
+
#
|
11
|
+
StationTogether2 - Unused.
|
2
12
|
class Station < Resource
|
3
13
|
service "Rail"
|
4
14
|
endpoint "JStations"
|
5
15
|
|
6
|
-
|
7
|
-
|
8
|
-
:blue => "BL",
|
9
|
-
:orange => "OR",
|
10
|
-
:green => "GR",
|
11
|
-
:yellow => "YE"
|
12
|
-
}
|
13
|
-
|
16
|
+
# Get all stations on a given line; argument can be a +Line+ instance, a string
|
17
|
+
# line code, or a symbol name (e.g., +:red+).
|
14
18
|
def self.get_on_line(line)
|
15
|
-
line =
|
19
|
+
line = Line.symbol_to_line_code(line) if line.is_a?(Symbol)
|
16
20
|
get_all("LineCode" => line.to_s)
|
17
21
|
end
|
18
22
|
|
23
|
+
# Get a specific station by its code.
|
19
24
|
def self.get(code)
|
20
25
|
url = WMATA.base_url % [service, "JStationInfo", to_query_string("StationCode" => code)]
|
21
26
|
new(HTTParty.get(url))
|
22
27
|
end
|
23
28
|
|
29
|
+
# Get all possible codes for this station (some stations are in together with another so
|
30
|
+
# they are technically identified by two station codes).
|
24
31
|
def codes
|
25
32
|
[@attrs['Code'], @attrs['StationTogether1'], @attrs['StationTogether2']].compact
|
26
33
|
end
|
27
34
|
|
35
|
+
# Get the line codes for this station (some stations serve more than one line).
|
28
36
|
def line_codes
|
29
37
|
[@attrs['LineCode1'], @attrs['LineCode2'], @attrs['LineCode3'], @attrs['LineCode4']].compact
|
30
38
|
end
|
31
39
|
|
40
|
+
# Get +Line+ instances for the lines serviced by this station.
|
32
41
|
def lines
|
33
42
|
@lines ||= line_codes.map {|l| Line.get(l)}
|
34
43
|
end
|
35
44
|
|
45
|
+
# Get train arrival predictions for this station.
|
36
46
|
def predictions
|
37
47
|
@predictions ||= Prediction.predict_for(self)
|
38
48
|
end
|
39
49
|
|
50
|
+
# Get all elevator incidents affecting this station.
|
40
51
|
def elevator_incidents
|
41
52
|
@elevator_incidents ||= ElevatorIncident.get_by_station(self)
|
42
53
|
end
|
43
54
|
|
55
|
+
# Build a path from this station to another identified by its code or as a
|
56
|
+
# +Station+ instance.
|
57
|
+
def path_to(to)
|
58
|
+
WMATA.build_path(self, to)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Build a path from this station to another station identified by its code
|
62
|
+
# or as a +Station+ instance.
|
63
|
+
def path_from(from)
|
64
|
+
WMATA.build_path(from, self)
|
65
|
+
end
|
66
|
+
|
67
|
+
def latitude
|
68
|
+
@attrs['Lat']
|
69
|
+
end
|
70
|
+
|
71
|
+
def longitude
|
72
|
+
@attrs['Lon']
|
73
|
+
end
|
74
|
+
|
75
|
+
def coordinates
|
76
|
+
[latitude, longitude]
|
77
|
+
end
|
78
|
+
|
79
|
+
alias_method :coords, :coordinates
|
80
|
+
|
44
81
|
def to_s
|
45
82
|
@attrs['Code']
|
46
83
|
end
|
@@ -1,14 +1,40 @@
|
|
1
1
|
module WMATA
|
2
|
+
# A resource class representing a station entrance (even if it's just an elevator).
|
3
|
+
#
|
4
|
+
# Available attribute methods:
|
5
|
+
#
|
6
|
+
# * +id+ - ID of the entrance.
|
7
|
+
# * +name+ - The name of the entrance.
|
8
|
+
# * +description+ - A description of the entrance.
|
9
|
+
# * +lat+ - The entrance's latitude.
|
10
|
+
# * +lon+ - The entrance's longitude.
|
11
|
+
#
|
2
12
|
class StationEntrance < Resource
|
3
13
|
service "Rail"
|
4
14
|
endpoint "JStationEntrances"
|
5
15
|
|
16
|
+
# Get station codes that this entrance serves.
|
6
17
|
def station_codes
|
7
18
|
[@attrs['StationCode1'], @attrs['StationCode2']].compact
|
8
19
|
end
|
9
20
|
|
21
|
+
# Get the +Station+ instance for this entrance.
|
10
22
|
def station
|
11
23
|
@station ||= Station.get(station_codes.first)
|
12
24
|
end
|
25
|
+
|
26
|
+
def latitude
|
27
|
+
@attrs['Lat']
|
28
|
+
end
|
29
|
+
|
30
|
+
def longitude
|
31
|
+
@attrs['Lon']
|
32
|
+
end
|
33
|
+
|
34
|
+
def coordinates
|
35
|
+
[latitude, longitude]
|
36
|
+
end
|
37
|
+
|
38
|
+
alias_method :coords, :coordinates
|
13
39
|
end
|
14
40
|
end
|
data/lib/wmata.rb
CHANGED
@@ -18,45 +18,105 @@ module WMATA
|
|
18
18
|
|
19
19
|
class <<self
|
20
20
|
attr_accessor :api_key
|
21
|
-
|
21
|
+
|
22
|
+
# Get the base URL based on the API key given. Used in
|
23
|
+
# nearly every method that contacts the remote API.
|
22
24
|
def base_url
|
23
25
|
BASE_URL.dup % ["%s", "%s", @api_key, "%s"]
|
24
26
|
end
|
25
27
|
|
28
|
+
# Get all rail lines.
|
29
|
+
#
|
30
|
+
# WMATA.lines.map {|l| l.code}
|
31
|
+
# # => ["RD", "BL", "GR", "OR", "YE"]
|
32
|
+
#
|
26
33
|
def lines
|
27
34
|
Line.get_all
|
28
35
|
end
|
29
36
|
|
37
|
+
# Get all stations.
|
38
|
+
#
|
39
|
+
# WMATA.stations.map {|s| s.name }
|
40
|
+
# # => ["McPherson Square", "Metro Center", ...]
|
41
|
+
#
|
30
42
|
def stations
|
31
43
|
Station.get_all
|
32
44
|
end
|
33
45
|
|
46
|
+
# Get a specific station by code.
|
47
|
+
#
|
48
|
+
# WMATA.station("C02")
|
49
|
+
# # => #<Station:0x1205aee8 "McPherson Square">
|
50
|
+
#
|
34
51
|
def station(code)
|
35
52
|
Station.get(code)
|
36
53
|
end
|
37
54
|
|
55
|
+
# Get an array of stations on a particular line. Can be called
|
56
|
+
# with a line code (e.g., RD) or a symbol for the line name
|
57
|
+
# (e.g., +:red+).
|
58
|
+
#
|
59
|
+
# WMATA.stations_on_line(:red)
|
60
|
+
# # => [#<Station:0x0702aca8>, ...]
|
61
|
+
#
|
38
62
|
def stations_on_line(code)
|
39
63
|
Station.get_on_line(code)
|
40
64
|
end
|
41
65
|
|
66
|
+
# Get station predictions (i.e., train arrival information seen on
|
67
|
+
# station terminals) for a specific station; if no station
|
68
|
+
# code is provided, it will get predictions for all stations.
|
69
|
+
#
|
70
|
+
# predictions = WMATA.predict_for("C02")
|
71
|
+
# # => [#<Prediction:0x1205aee8 ...>, ...]
|
72
|
+
# puts "#{predictions.first.location_name} => #{predictions.first.destination_name}"
|
73
|
+
# # McPherson Square => Metro Center
|
74
|
+
#
|
42
75
|
def predict_for(station="All")
|
43
76
|
Prediction.predict_for(station)
|
44
77
|
end
|
45
78
|
|
79
|
+
alias_method :get_predictions, :predict_for
|
80
|
+
|
81
|
+
# Get an array of rail incidents for all lines; use the +incidents+ method
|
82
|
+
# on +Line+ to get them for a specific line or the same method.
|
83
|
+
#
|
84
|
+
# WMATA.rail_incidents.map {|i| i.description}
|
85
|
+
# # => ["Friendship Heights is closed...", ...]
|
86
|
+
#
|
46
87
|
def rail_incidents
|
47
88
|
RailIncident.get_all
|
48
89
|
end
|
49
90
|
|
50
91
|
alias_method :incidents, :rail_incidents
|
51
92
|
|
93
|
+
# Get an array of elevator incidents for all lines; use the +elevator_incidents+
|
94
|
+
# method on +Station+ to get them for a specific station.
|
95
|
+
#
|
96
|
+
# WMATA.elevator_incidents.map {|i| i.symptom_code}
|
97
|
+
# # => ["1419", ...]
|
98
|
+
#
|
52
99
|
def elevator_incidents
|
53
100
|
ElevatorIncident.get_all
|
54
101
|
end
|
55
102
|
|
103
|
+
# Map a path between two stations, identified by their station codes; returns an
|
104
|
+
# array of stations ordered by the path. You can also provide +Station+ instances
|
105
|
+
# and get a path between them.
|
106
|
+
#
|
107
|
+
# WMATA.build_path("C02", "A01")
|
108
|
+
# # => [#<Station:0x0702aca8>, ...]
|
109
|
+
#
|
56
110
|
def build_path(from, to)
|
57
111
|
PathSegment.get_all("FromStationCode" => from, "ToStationCode" => to)
|
58
112
|
end
|
59
113
|
|
114
|
+
# Find entrances near a given latitude and longitude within a given radius (in meters).
|
115
|
+
# If no geolocation information is given, all entrances are returned.
|
116
|
+
#
|
117
|
+
# WMATA.entrances(:lat => 28.82083, :lon => 88.9239423, :radius => 2000)
|
118
|
+
# # => [#<StationEntrance:0x0702aca8>, ...]
|
119
|
+
#
|
60
120
|
def entrances(from={})
|
61
121
|
params = {:lat => 0, :lon => 0, :radius => 500}.merge(from)
|
62
122
|
StationEntrance.get_all(params)
|
data/wmata.gemspec
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{wmata}
|
8
|
+
s.version = "0.2.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Jeremy McAnally"]
|
12
|
+
s.date = %q{2010-08-17}
|
13
|
+
s.description = %q{A gem for accessing the WMATA API}
|
14
|
+
s.email = %q{jeremymcanally@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/resource.rb",
|
27
|
+
"lib/resources/elevator_incident.rb",
|
28
|
+
"lib/resources/line.rb",
|
29
|
+
"lib/resources/path_segment.rb",
|
30
|
+
"lib/resources/prediction.rb",
|
31
|
+
"lib/resources/rail_incident.rb",
|
32
|
+
"lib/resources/station.rb",
|
33
|
+
"lib/resources/station_entrance.rb",
|
34
|
+
"lib/wmata.rb",
|
35
|
+
"test/helper.rb",
|
36
|
+
"test/test_elevator_incident.rb",
|
37
|
+
"test/test_line.rb",
|
38
|
+
"test/test_path_segment.rb",
|
39
|
+
"test/test_prediction.rb",
|
40
|
+
"test/test_rail_incident.rb",
|
41
|
+
"test/test_resource.rb",
|
42
|
+
"test/test_station.rb",
|
43
|
+
"test/test_station_entrance.rb",
|
44
|
+
"test/test_wmata.rb",
|
45
|
+
"wmata.gemspec"
|
46
|
+
]
|
47
|
+
s.homepage = %q{http://github.com/jm/wmata}
|
48
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
49
|
+
s.require_paths = ["lib"]
|
50
|
+
s.rubygems_version = %q{1.3.6}
|
51
|
+
s.summary = %q{A gem for the WMATA API}
|
52
|
+
s.test_files = [
|
53
|
+
"test/helper.rb",
|
54
|
+
"test/test_elevator_incident.rb",
|
55
|
+
"test/test_line.rb",
|
56
|
+
"test/test_path_segment.rb",
|
57
|
+
"test/test_prediction.rb",
|
58
|
+
"test/test_rail_incident.rb",
|
59
|
+
"test/test_resource.rb",
|
60
|
+
"test/test_station.rb",
|
61
|
+
"test/test_station_entrance.rb",
|
62
|
+
"test/test_wmata.rb"
|
63
|
+
]
|
64
|
+
|
65
|
+
if s.respond_to? :specification_version then
|
66
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
67
|
+
s.specification_version = 3
|
68
|
+
|
69
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
70
|
+
else
|
71
|
+
end
|
72
|
+
else
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 2
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jeremy McAnally
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-08-
|
17
|
+
date: 2010-08-17 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -53,6 +53,7 @@ files:
|
|
53
53
|
- test/test_station.rb
|
54
54
|
- test/test_station_entrance.rb
|
55
55
|
- test/test_wmata.rb
|
56
|
+
- wmata.gemspec
|
56
57
|
has_rdoc: true
|
57
58
|
homepage: http://github.com/jm/wmata
|
58
59
|
licenses: []
|