mbta 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.DS_Store +0 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +35 -0
- data/Rakefile +2 -0
- data/data/.DS_Store +0 -0
- data/data/RealTimeHeavyRailKeys.csv +101 -0
- data/lib/mbta/version.rb +3 -0
- data/lib/mbta.rb +191 -0
- data/mbta.gemspec +17 -0
- metadata +57 -0
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Chris Kalafarski
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Mbta
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'mbta'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install mbta
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Basic example:
|
22
|
+
|
23
|
+
json = HTTParty.get('http://developer.mbta.com/Data/Red.json')
|
24
|
+
MBTA::HeavyRail::System::MAP.lines['Red'].parse_announcements(json)
|
25
|
+
|
26
|
+
p MBTA::RedLine['Harvard'][:northbound].predictions.first.time
|
27
|
+
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
1. Fork it
|
32
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
33
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
34
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
35
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/data/.DS_Store
ADDED
Binary file
|
@@ -0,0 +1,101 @@
|
|
1
|
+
Line,PlatformKey,PlatformName,StationName,PlatformOrder,StartOfLine,EndOfLine,Branch,Direction,stop_id,stop_code,stop_name,stop_desc,stop_lat,stop_lon
|
2
|
+
Red,RALEN,ALEWIFE NB,ALEWIFE,17,FALSE,TRUE,Trunk,NB,place-alfcl,,Alewife Station,,42.395428,-71.142483
|
3
|
+
Red,RDAVN,DAVIS NB,DAVIS,16,FALSE,FALSE,Trunk,NB,place-davis,,Davis Station,,42.39674,-71.121815
|
4
|
+
Red,RDAVS,DAVIS SB,DAVIS,1,TRUE,FALSE,Trunk,SB,place-davis,,Davis Station,,42.39674,-71.121815
|
5
|
+
Red,RPORN,PORTER NB,PORTER,15,FALSE,FALSE,Trunk,NB,place-portr,,Porter Square Station,,42.3884,-71.119149
|
6
|
+
Red,RPORS,PORTER SB,PORTER,2,FALSE,FALSE,Trunk,SB,place-portr,,Porter Square Station,,42.3884,-71.119149
|
7
|
+
Red,RHARN,HARVARD NB,HARVARD,14,FALSE,FALSE,Trunk,NB,place-harsq,,Harvard Square Station,,42.373362,-71.118956
|
8
|
+
Red,RHARS,HARVARD SB,HARVARD,3,FALSE,FALSE,Trunk,SB,place-harsq,,Harvard Square Station,,42.373362,-71.118956
|
9
|
+
Red,RCENN,CENTRAL NB,CENTRAL,13,FALSE,FALSE,Trunk,NB,place-cntsq,,Central Square Station,,42.365486,-71.103802
|
10
|
+
Red,RCENS,CENTRAL SB,CENTRAL,4,FALSE,FALSE,Trunk,SB,place-cntsq,,Central Square Station,,42.365486,-71.103802
|
11
|
+
Red,RKENN,KENDALL NB,KENDALL,12,FALSE,FALSE,Trunk,NB,place-knncl,,Kendall/MIT Station,,42.36249079,-71.08617653
|
12
|
+
Red,RKENS,KENDALL SB,KENDALL,5,FALSE,FALSE,Trunk,SB,place-knncl,,Kendall/MIT Station,,42.36249079,-71.08617653
|
13
|
+
Red,RMGHN,CHARLES MGH NB,CHARLES MGH,11,FALSE,FALSE,Trunk,NB,place-chmnl,,Charles/MGH Station,,42.361166,-71.070628
|
14
|
+
Red,RMGHS,CHARLES MGH SB,CHARLES MGH,6,FALSE,FALSE,Trunk,SB,place-chmnl,,Charles/MGH Station,,42.361166,-71.070628
|
15
|
+
Red,RPRKN,PARK NB,PARK,10,FALSE,FALSE,Trunk,NB,place-pktrm,,Park St. Station,,42.35639457,-71.0624242
|
16
|
+
Red,RPRKS,PARK SB,PARK,7,FALSE,FALSE,Trunk,SB,place-pktrm,,Park St. Station,,42.35639457,-71.0624242
|
17
|
+
Red,RDTCN,DOWNTOWN CROSSING NB,DOWNTOWN CROSSING,9,FALSE,FALSE,Trunk,NB,place-dwnxg,,Downtown Crossing Station,,42.355518,-71.060225
|
18
|
+
Red,RDTCS,DOWNTOWN CROSSING SB,DOWNTOWN CROSSING,8,FALSE,FALSE,Trunk,SB,place-dwnxg,,Downtown Crossing Station,,42.355518,-71.060225
|
19
|
+
Red,RSOUN,SOUTH STATION NB,SOUTH STATION,8,FALSE,FALSE,Trunk,NB,place-sstat,,South Station,,42.352271,-71.055242
|
20
|
+
Red,RSOUS,SOUTH STATION SB,SOUTH STATION,9,FALSE,FALSE,Trunk,SB,place-sstat,,South Station,,42.352271,-71.055242
|
21
|
+
Red,RBRON,BROADWAY NB,BROADWAY,7,FALSE,FALSE,Trunk,NB,place-brdwy,,Broadway Station,,42.342622,-71.056967
|
22
|
+
Red,RBROS,BROADWAY SB,BROADWAY,10,FALSE,FALSE,Trunk,SB,place-brdwy,,Broadway Station,,42.342622,-71.056967
|
23
|
+
Red,RANDN,ANDREW NB,ANDREW,6,FALSE,FALSE,Trunk,NB,place-andrw,,Andrew Station,,42.330154,-71.057655
|
24
|
+
Red,RANDS,ANDREW SB,ANDREW,11,FALSE,FALSE,Trunk,SB,place-andrw,,Andrew Station,,42.330154,-71.057655
|
25
|
+
Red,RJFKN,JFK NB,JFK,5,FALSE,FALSE,Trunk,NB,place-jfkred,,JFK/UMass Station,,42.320685,-71.052391
|
26
|
+
Red,RJFKS,JFK SB,JFK,12,FALSE,FALSE,Trunk,SB,place-jfkred,,JFK/UMass Station,,42.320685,-71.052391
|
27
|
+
Red,RSAVN,SAVIN HILL NB,SAVIN HILL,4,FALSE,FALSE,Ashmont,NB,place-shmnl,,Savin Hill Station,,42.31129,-71.053331
|
28
|
+
Red,RSAVS,SAVIN HILL SB,SAVIN HILL,13,FALSE,FALSE,Ashmont,SB,place-shmnl,,Savin Hill Station,,42.31129,-71.053331
|
29
|
+
Red,RFIEN,FIELDS CORNER NB,FIELDS CORNER,3,FALSE,FALSE,Ashmont,NB,place-fldcr,,Fields Corner Station,,42.300093,-71.061667
|
30
|
+
Red,RFIES,FIELDS CORNER SB,FIELDS CORNER,14,FALSE,FALSE,Ashmont,SB,place-fldcr,,Fields Corner Station,,42.300093,-71.061667
|
31
|
+
Red,RSHAN,SHAWMUT NB,SHAWMUT,2,TRUE,FALSE,Ashmont,NB,place-smmnl,,Shawmut Station,,42.29312583,-71.06573796
|
32
|
+
Red,RSHAS,SHAWMUT SB,SHAWMUT,15,FALSE,FALSE,Ashmont,SB,place-smmnl,,Shawmut Station,,42.29312583,-71.06573796
|
33
|
+
Red,RASHS,ASHMONT SB,ASHMONT,16,FALSE,TRUE,Ashmont,SB,place-asmnl,,Ashmont Station,,42.284652,-71.064489
|
34
|
+
Red,RNQUN,NORTH QUINCY NB,NORTH QUINCY,4,FALSE,FALSE,Braintree,NB,place-nqncy,,North Quincy Station,,42.275275,-71.029583
|
35
|
+
Red,RNQUS,NORTH QUINCY SB,NORTH QUINCY,13,FALSE,FALSE,Braintree,SB,place-nqncy,,North Quincy Station,,42.275275,-71.029583
|
36
|
+
Red,RWOLN,WOLLASTON NB,WOLLASTON,3,FALSE,FALSE,Braintree,NB,place-wlsta,,Wollaston Station,,42.2665139,-71.0203369
|
37
|
+
Red,RWOLS,WOLLASTON SB,WOLLASTON,14,FALSE,FALSE,Braintree,SB,place-wlsta,,Wollaston Station,,42.2665139,-71.0203369
|
38
|
+
Red,RQUCN,QUINCY CENTER NB,QUINCY CENTER,2,FALSE,FALSE,Braintree,NB,place-qnctr,,Quincy Center Station,,42.251809,-71.005409
|
39
|
+
Red,RQUCS,QUINCY CENTER SB,QUINCY CENTER,15,FALSE,FALSE,Braintree,SB,place-qnctr,,Quincy Center Station,,42.251809,-71.005409
|
40
|
+
Red,RQUAN,QUINCY ADAMS NB,QUINCY ADAMS,1,TRUE,FALSE,Braintree,NB,place-qamnl,,Quincy Adams Station,,42.233391,-71.007153
|
41
|
+
Red,RQUAS,QUINCY ADAMS SB,QUINCY ADAMS,16,FALSE,FALSE,Braintree,SB,place-qamnl,,Quincy Adams Station,,42.233391,-71.007153
|
42
|
+
Red,RBRAS,BRAINTREE SB,BRAINTREE,17,FALSE,TRUE,Braintree,SB,place-brntn,,Braintree Station,,42.2078543,-71.0011385
|
43
|
+
Orange,OOAKN,OAK GROVE NB,OAK GROVE,18,FALSE,TRUE,Trunk,NB,place-ogmnl,,Oak Grove Station,,42.43668,-71.071097
|
44
|
+
Orange,OMALN,MALDEN NB,MALDEN,17,FALSE,FALSE,Trunk,NB,place-mlmnl,,Malden Center Station,,42.426632,-71.07411
|
45
|
+
Orange,OMALS,MALDEN SB,MALDEN,1,TRUE,FALSE,Trunk,SB,place-mlmnl,,Malden Center Station,,42.426632,-71.07411
|
46
|
+
Orange,OWELN,WELLINGTON NB,WELLINGTON,16,FALSE,FALSE,Trunk,NB,place-welln,,Wellington Station,,42.40237,-71.077082
|
47
|
+
Orange,OWELS,WELLINGTON SB,WELLINGTON,2,FALSE,FALSE,Trunk,SB,place-welln,,Wellington Station,,42.40237,-71.077082
|
48
|
+
Orange,OSULN,SULLIVAN NB,SULLIVAN,15,FALSE,FALSE,Trunk,NB,place-sull,,Sullivan Station,,42.383975,-71.076994
|
49
|
+
Orange,OSULS,SULLIVAN SB,SULLIVAN,3,FALSE,FALSE,Trunk,SB,place-sull,,Sullivan Station,,42.383975,-71.076994
|
50
|
+
Orange,OCOMN,COMMUNITY NB,COMMUNITY,14,FALSE,FALSE,Trunk,NB,place-ccmnl,,Community College Station,,42.373622,-71.069533
|
51
|
+
Orange,OCOMS,COMMUNITY SB,COMMUNITY,4,FALSE,FALSE,Trunk,SB,place-ccmnl,,Community College Station,,42.373622,-71.069533
|
52
|
+
Orange,ONSTN,NORTH STATION NB,NORTH STATION,13,FALSE,FALSE,Trunk,NB,place-north,,North Station,,42.365577,-71.06129
|
53
|
+
Orange,ONSTS,NORTH STATION SB,NORTH STATION,5,FALSE,FALSE,Trunk,SB,place-north,,North Station,,42.365577,-71.06129
|
54
|
+
Orange,OHAYN,HAYMARKET NB,HAYMARKET,12,FALSE,FALSE,Trunk,NB,place-haecl,,Haymarket Station,,42.363021,-71.05829
|
55
|
+
Orange,OHAYS,HAYMARKET SB,HAYMARKET,6,FALSE,FALSE,Trunk,SB,place-haecl,,Haymarket Station,,42.363021,-71.05829
|
56
|
+
Orange,OSTNN,STATE NB,STATE,11,FALSE,FALSE,Trunk,NB,place-state,,State St. Station,,42.358978,-71.057598
|
57
|
+
Orange,OSTSS,STATE SB,STATE,7,FALSE,FALSE,Trunk,SB,place-state,,State St. Station,,42.358978,-71.057598
|
58
|
+
Orange,ODTNN,DOWNTOWN CROSSING NB,DOWNTOWN CROSSING,10,FALSE,FALSE,Trunk,NB,place-dwnxg,,Downtown Crossing Station,,42.355518,-71.060225
|
59
|
+
Orange,ODTSS,DOWNTOWN CROSSING SB,DOWNTOWN CROSSING,8,FALSE,FALSE,Trunk,SB,place-dwnxg,,Downtown Crossing Station,,42.355518,-71.060225
|
60
|
+
Orange,OCHNN,CHINATOWN NB,CHINATOWN,9,FALSE,FALSE,Trunk,NB,place-chncl,,Chinatown Station,,42.352547,-71.062752
|
61
|
+
Orange,OCHSS,CHINATOWN SB,CHINATOWN,9,FALSE,FALSE,Trunk,SB,place-chncl,,Chinatown Station,,42.352547,-71.062752
|
62
|
+
Orange,ONEMN,TUFTS MEDICAL CENTER NB,TUFTS MEDICAL CENTER,8,FALSE,FALSE,Trunk,NB,place-nemnl,,Tufts Medical Center Station,,42.349662,-71.063917
|
63
|
+
Orange,ONEMS,TUFTS MEDICAL CENTER SB,TUFTS MEDICAL CENTER,10,FALSE,FALSE,Trunk,SB,place-nemnl,,Tufts Medical Center Station,,42.349662,-71.063917
|
64
|
+
Orange,OBACN,BACK BAY NB,BACK BAY,7,FALSE,FALSE,Trunk,NB,place-bbsta,,Back Bay Station,,42.34735,-71.075727
|
65
|
+
Orange,OBACS,BACK BAY SB,BACK BAY,11,FALSE,FALSE,Trunk,SB,place-bbsta,,Back Bay Station,,42.34735,-71.075727
|
66
|
+
Orange,OMASN,MASS AVE NB,MASS AVE,6,FALSE,FALSE,Trunk,NB,place-masta,,Massachusetts Ave. Station,,42.341512,-71.083423
|
67
|
+
Orange,OMASS,MASS AVE SB,MASS AVE,12,FALSE,FALSE,Trunk,SB,place-masta,,Massachusetts Ave. Station,,42.341512,-71.083423
|
68
|
+
Orange,ORUGN,RUGGLES NB,RUGGLES,5,FALSE,FALSE,Trunk,NB,place-rugg,,Ruggles Station,,42.336377,-71.088961
|
69
|
+
Orange,ORUGS,RUGGLES SB,RUGGLES,13,FALSE,FALSE,Trunk,SB,place-rugg,,Ruggles Station,,42.336377,-71.088961
|
70
|
+
Orange,OROXN,ROXBURY NB,ROXBURY,4,FALSE,FALSE,Trunk,NB,place-rcmnl,,Roxbury Crossing Station,,42.331397,-71.095451
|
71
|
+
Orange,OROXS,ROXBURY SB,ROXBURY,14,FALSE,FALSE,Trunk,SB,place-rcmnl,,Roxbury Crossing Station,,42.331397,-71.095451
|
72
|
+
Orange,OJACN,JACKSON NB,JACKSON,3,FALSE,FALSE,Trunk,NB,place-jaksn,,Jackson Square Station,,42.323132,-71.099592
|
73
|
+
Orange,OJACS,JACKSON SB,JACKSON,15,FALSE,FALSE,Trunk,SB,place-jaksn,,Jackson Square Station,,42.323132,-71.099592
|
74
|
+
Orange,OSTON,STONY BROOK NB,STONY BROOK,2,FALSE,FALSE,Trunk,NB,place-sbmnl,,Stony Brook Station,,42.317062,-71.104248
|
75
|
+
Orange,OSTOS,STONY BROOK SB,STONY BROOK,16,FALSE,FALSE,Trunk,SB,place-sbmnl,,Stony Brook Station,,42.317062,-71.104248
|
76
|
+
Orange,OGREN,GREEN STREET NB,GREEN STREET,1,TRUE,FALSE,Trunk,NB,place-grnst,,Green St. Station,,42.310525,-71.107414
|
77
|
+
Orange,OGRES,GREEN STREET SB,GREEN STREET,17,FALSE,FALSE,Trunk,SB,place-grnst,,Green St. Station,,42.310525,-71.107414
|
78
|
+
Orange,OFORS,FOREST HILLS SB,FOREST HILLS,18,FALSE,TRUE,Trunk,SB,place-forhl,,Forest Hills Station,,42.300523,-71.113686
|
79
|
+
Blue,BWONE,WONDERLAND EB,WONDERLAND,12,FALSE,TRUE,Trunk,EB,place-wondl,,Wonderland Station,,42.41342,-70.991648
|
80
|
+
Blue,BREVE,REVERE EB,REVERE,11,FALSE,FALSE,Trunk,EB,place-rbmnl,,Revere Beach Station,,42.40784254,-70.99253321
|
81
|
+
Blue,BREVW,REVERE WB,REVERE,1,TRUE,FALSE,Trunk,WB,place-rbmnl,,Revere Beach Station,,42.40784254,-70.99253321
|
82
|
+
Blue,BBEAE,BEACHMONT EB,BEACHMONT,10,FALSE,FALSE,Trunk,EB,place-bmmnl,,Beachmont Station,,42.39754234,-70.99231944
|
83
|
+
Blue,BBEAW,BEACHMONT WB,BEACHMONT,2,FALSE,FALSE,Trunk,WB,place-bmmnl,,Beachmont Station,,42.39754234,-70.99231944
|
84
|
+
Blue,BSUFE,SUFFOLK DOWNS EB,SUFFOLK DOWNS,9,FALSE,FALSE,Trunk,EB,place-sdmnl,,Suffolk Downs Station,,42.39050067,-70.99712259
|
85
|
+
Blue,BSUFW,SUFFOLK DOWNS WB,SUFFOLK DOWNS,3,FALSE,FALSE,Trunk,WB,place-sdmnl,,Suffolk Downs Station,,42.39050067,-70.99712259
|
86
|
+
Blue,BORHE,ORIENT HEIGHTS EB,ORIENT HEIGHTS,8,FALSE,FALSE,Trunk,EB,place-orhte,,Orient Heights Station,,42.386867,-71.004736
|
87
|
+
Blue,BORHW,ORIENT HEIGHTS WB,ORIENT HEIGHTS,4,FALSE,FALSE,Trunk,WB,place-orhte,,Orient Heights Station,,42.386867,-71.004736
|
88
|
+
Blue,BWOOE,WOOD ISLAND EB,WOOD ISLAND,7,FALSE,FALSE,Trunk,EB,place-wimnl,,Wood Island Station,,42.3796403,-71.02286539
|
89
|
+
Blue,BWOOW,WOOD ISLAND WB,WOOD ISLAND,5,FALSE,FALSE,Trunk,WB,place-wimnl,,Wood Island Station,,42.3796403,-71.02286539
|
90
|
+
Blue,BAIRE,AIRPORT EB,AIRPORT,6,FALSE,FALSE,Trunk,EB,place-aport,,Airport Station,,42.374262,-71.030395
|
91
|
+
Blue,BAIRW,AIRPORT WB,AIRPORT,6,FALSE,FALSE,Trunk,WB,place-aport,,Airport Station,,42.374262,-71.030395
|
92
|
+
Blue,BMAVE,MAVERICK EB,MAVERICK,5,FALSE,FALSE,Trunk,EB,place-mvbcl,,Maverick Station,,42.36911856,-71.03952958
|
93
|
+
Blue,BMAVW,MAVERICK WB,MAVERICK,7,FALSE,FALSE,Trunk,WB,place-mvbcl,,Maverick Station,,42.36911856,-71.03952958
|
94
|
+
Blue,BAQUE,AQUARIUM EB,AQUARIUM,4,FALSE,FALSE,Trunk,EB,place-aqucl,,Aquarium Station,,42.359784,-71.051652
|
95
|
+
Blue,BAQUW,AQUARIUM WB,AQUARIUM,8,FALSE,FALSE,Trunk,WB,place-aqucl,,Aquarium Station,,42.359784,-71.051652
|
96
|
+
Blue,BSTAE,STATE EB,STATE,3,FALSE,FALSE,Trunk,EB,place-state,,State St. Station,,42.358978,-71.057598
|
97
|
+
Blue,BSTAW,STATE WB,STATE,9,FALSE,FALSE,Trunk,WB,place-state,,State St. Station,,42.358978,-71.057598
|
98
|
+
Blue,BGOVE,GOVERNMENT CENTER EB,GOVERNMENT CENTER,2,FALSE,FALSE,Trunk,EB,place-gover,,Government Center Station,,42.359705,-71.059215
|
99
|
+
Blue,BGOVW,GOVERNMENT CENTER WB,GOVERNMENT CENTER,10,FALSE,FALSE,Trunk,WB,place-gover,,Government Center Station,,42.359705,-71.059215
|
100
|
+
Blue,BBOWE,BOWDOIN EB,BOWDOIN,1,TRUE,FALSE,Trunk,EB,place-bomnl,,Bowdoin Station,,42.361365,-71.062037
|
101
|
+
Blue,BBOWW,BOWDOIN WB,BOWDOIN,11,FALSE,TRUE,Trunk,WB,place-bomnl,,Bowdoin Station,,42.361365,-71.062037
|
data/lib/mbta/version.rb
ADDED
data/lib/mbta.rb
ADDED
@@ -0,0 +1,191 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'json'
|
3
|
+
require 'csv'
|
4
|
+
require 'pp'
|
5
|
+
|
6
|
+
require "mbta/version"
|
7
|
+
|
8
|
+
module MBTA
|
9
|
+
module HeavyRail
|
10
|
+
module Announcements
|
11
|
+
class Base
|
12
|
+
attr_reader :trip, :platform, :time
|
13
|
+
|
14
|
+
def initialize(trip, platform, time)
|
15
|
+
@trip = trip
|
16
|
+
@platform = platform
|
17
|
+
@time = time
|
18
|
+
end
|
19
|
+
|
20
|
+
def type
|
21
|
+
self.class.name.split('::').last.downcase.to_sym
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Prediction < Base
|
26
|
+
end
|
27
|
+
|
28
|
+
class Arrival < Base
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class Line
|
33
|
+
attr_reader :name, :color
|
34
|
+
attr_writer :stations
|
35
|
+
attr_accessor :trips
|
36
|
+
|
37
|
+
def initialize(name, stations = {})
|
38
|
+
@name = name
|
39
|
+
@color = name.downcase.to_sym
|
40
|
+
@stations = stations
|
41
|
+
@trips = {}
|
42
|
+
end
|
43
|
+
|
44
|
+
def stations(name_or_direction = nil)
|
45
|
+
case name_or_direction
|
46
|
+
when String then self[name_or_direction]
|
47
|
+
when Symbol then nil
|
48
|
+
else @stations
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def [](name_or_key)
|
53
|
+
case name_or_key
|
54
|
+
when String then @stations.find { |station| station.name == name_or_key }
|
55
|
+
when Symbol then platforms.find { |platform| platform.key == name_or_key }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def platforms
|
60
|
+
stations.inject(Array.new) { |memo, station| memo << station.platforms }.flatten
|
61
|
+
end
|
62
|
+
|
63
|
+
def parse_announcements(json)
|
64
|
+
data = JSON.parse(json)
|
65
|
+
_trips = data.inject(Array.new) { |memo, announcement| memo << announcement['Trip'].to_i }.uniq
|
66
|
+
_trips.each do |trip|
|
67
|
+
self.trips[trip] = MBTA::HeavyRail::Trip.new(self, trip)
|
68
|
+
end
|
69
|
+
|
70
|
+
data.each do |a|
|
71
|
+
trip = self.trips[a['Trip'].to_i]
|
72
|
+
time = Time.strptime(a['Time'], '%m/%d/%Y %H:%M:%S %p')
|
73
|
+
platform = self[a['PlatformKey'].downcase.to_sym]
|
74
|
+
|
75
|
+
announcement_type = case a['InformationType']
|
76
|
+
when 'Arrived' then MBTA::HeavyRail::Announcements::Arrival
|
77
|
+
when 'Predicted' then MBTA::HeavyRail::Announcements::Prediction
|
78
|
+
end
|
79
|
+
|
80
|
+
trip.announcements << announcement_type.new(trip, platform, time) if announcement_type
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
class Trip
|
86
|
+
attr_reader :line, :id
|
87
|
+
attr_accessor :announcements
|
88
|
+
|
89
|
+
def initialize(line, id)
|
90
|
+
@line = line
|
91
|
+
@id = id
|
92
|
+
@announcements = []
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
class Station
|
97
|
+
attr_reader :line, :name
|
98
|
+
attr_writer :platforms
|
99
|
+
|
100
|
+
def initialize(line, name, platforms = [])
|
101
|
+
@line = line
|
102
|
+
@name = name
|
103
|
+
@platforms = platforms
|
104
|
+
end
|
105
|
+
|
106
|
+
def platforms(direction = nil)
|
107
|
+
if (direction)
|
108
|
+
self[direction]
|
109
|
+
else
|
110
|
+
@platforms
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def [](direction)
|
115
|
+
@platforms.find { |platform| platform.direction == direction }
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
class Platform
|
120
|
+
attr_reader :station, :direction, :key
|
121
|
+
|
122
|
+
def initialize(station, direction, order, key)
|
123
|
+
@station = station
|
124
|
+
@direction = direction
|
125
|
+
@order = order
|
126
|
+
@key = key
|
127
|
+
end
|
128
|
+
|
129
|
+
def predictions
|
130
|
+
station.line.trips.inject(Array.new) do |memo, trip|
|
131
|
+
memo << trip[1].announcements.inject(Array.new) do |m, a|
|
132
|
+
m << a if (self.key == a.platform.key && a.type == :prediction)
|
133
|
+
m
|
134
|
+
end
|
135
|
+
end.flatten.compact.sort {|x, y| x.time <=> y.time }
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
module System
|
140
|
+
class Map
|
141
|
+
attr_reader :lines
|
142
|
+
|
143
|
+
def initialize(lines = {})
|
144
|
+
@lines = lines
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
class Builder
|
149
|
+
def initialize
|
150
|
+
@data = CSV.read("../data/RealTimeHeavyRailKeys.csv", { headers: true })
|
151
|
+
end
|
152
|
+
|
153
|
+
def map
|
154
|
+
data = @data
|
155
|
+
line_names = data.inject(Array.new) {|memo, platform| memo.push(platform['Line']) }.uniq
|
156
|
+
lines = line_names.map{|name| MBTA::HeavyRail::Line.new(name) }
|
157
|
+
|
158
|
+
lines.each do |line|
|
159
|
+
platforms = data.select {|row| row['Line'] == line.name }
|
160
|
+
station_names = platforms.inject(Array.new) {|memo, platform| memo.push(platform['StationName']) }.uniq
|
161
|
+
line.stations = station_names.map {|name| MBTA::HeavyRail::Station.new(line, name.capitalize) }
|
162
|
+
|
163
|
+
line.stations.each do |station|
|
164
|
+
data.select{|row| row['StationName'].capitalize == station.name }.each do |row|
|
165
|
+
direction = case row['Direction']
|
166
|
+
when 'NB' then :northbound
|
167
|
+
when 'SB' then :southbound
|
168
|
+
when 'EB' then :eastbound
|
169
|
+
when 'WB' then :westbound
|
170
|
+
end
|
171
|
+
key = row['PlatformKey'].downcase.to_sym
|
172
|
+
station.platforms.push(MBTA::HeavyRail::Platform.new(station, direction, row['PlatformOrder'], key))
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
_lines = lines.inject(Hash.new){|lines, line| lines[line.name] = line; lines }
|
178
|
+
|
179
|
+
map = MBTA::HeavyRail::System::Map.new(_lines)
|
180
|
+
return map
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
MAP = Builder.new.map
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
BlueLine = MBTA::HeavyRail::System::MAP.lines['Blue']
|
189
|
+
GreenLine = MBTA::HeavyRail::System::MAP.lines['Green']
|
190
|
+
RedLine = MBTA::HeavyRail::System::MAP.lines['Red']
|
191
|
+
end
|
data/mbta.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/mbta/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Chris Kalafarski"]
|
6
|
+
gem.email = ["chris@farski.com"]
|
7
|
+
gem.description = %q{Library for accessing real-time MBTA data}
|
8
|
+
gem.summary = %q{Not a product of the MBTA. See mbta.com/developers for more info about their API}
|
9
|
+
gem.homepage = "https://github.com/farski/mbta"
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "mbta"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = MBTA::VERSION
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mbta
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Chris Kalafarski
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-24 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Library for accessing real-time MBTA data
|
15
|
+
email:
|
16
|
+
- chris@farski.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .DS_Store
|
22
|
+
- .gitignore
|
23
|
+
- Gemfile
|
24
|
+
- LICENSE
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- data/.DS_Store
|
28
|
+
- data/RealTimeHeavyRailKeys.csv
|
29
|
+
- lib/mbta.rb
|
30
|
+
- lib/mbta/version.rb
|
31
|
+
- mbta.gemspec
|
32
|
+
homepage: https://github.com/farski/mbta
|
33
|
+
licenses: []
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
requirements: []
|
51
|
+
rubyforge_project:
|
52
|
+
rubygems_version: 1.8.11
|
53
|
+
signing_key:
|
54
|
+
specification_version: 3
|
55
|
+
summary: Not a product of the MBTA. See mbta.com/developers for more info about their
|
56
|
+
API
|
57
|
+
test_files: []
|