mbta-realtime 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8b0be0efe563e0c632bc4faa640b03dfe9055229
4
- data.tar.gz: 133680e195cbb5aebab0983a116f9a6fb8faf158
3
+ metadata.gz: 7502a15244bd9b2909ffaa3ffdedc7863cf5fa87
4
+ data.tar.gz: 7a218c049d825a54f47eddee4c24fcf9ade2f9a7
5
5
  SHA512:
6
- metadata.gz: d9a228a1af855ccf1e8ae6acca1f3f4497da277deef45d648b720286fb6a25a2d53e015f11fb98edd5a0e4f217a91567327f2bf132ddf913ab549f8950a4f585
7
- data.tar.gz: adb8612fd872592d06e463ae681a322ee293650ffe92b9f4fac778f97b3f8570eb45452d06b0233ddc96f8ad430337d1465a57ea866dfea29002fb794d7afeb7
6
+ metadata.gz: 66b1f0107cb808defb87069af8b73daa75ee99e534bdcebbf8d41709646ae292f3d5c7bfd53c5ac31302a9257dce722432e70fa574acb1bde73ce6c1c3424799
7
+ data.tar.gz: 5d9601b982ac5ca874db3a8b9cf6fd036cc22c852434a9fb4726598874ef139b339fa64216470f7a50b9b1e20ab0a33c08ec0e06bcf224f95a20cf289c50c348
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
@@ -75,8 +75,9 @@ module MBTARealtime
75
75
  end
76
76
 
77
77
 
78
- def predictions_by_stop(stop_id)
79
- raise NotImplementedError
78
+ def predictions_by_stop(stop_id, flatten=false)
79
+ ps = self.class.get("/predictionsbystop", url_opts({stop: stop_id})).to_h
80
+ flatten ? flatten_predictions(ps) : ps
80
81
  end
81
82
 
82
83
 
@@ -85,13 +86,9 @@ module MBTARealtime
85
86
  end
86
87
 
87
88
 
88
- def predictions_by_location(location)
89
- raise NotImplementedError
90
- end
91
-
92
-
93
- def predictions_by_location_name(intersection)
94
- raise NotImplementedError
89
+ def predictions_by_location_name(intersection, flatten=false)
90
+ ps = predictions_by_stop( nearest_stop_id_by_location_name(intersection) )
91
+ flatten ? flatten_predictions( ps ) : ps
95
92
  end
96
93
 
97
94
 
@@ -102,6 +99,29 @@ module MBTARealtime
102
99
  { query: @options[:query].merge( args ) }
103
100
  end
104
101
 
102
+ def flatten_predictions(predictions_response)
103
+ @predictions = []
104
+
105
+ travel_modes = predictions_response['mode']
106
+ travel_modes.each do |mode|
107
+ routes = mode['route']
108
+ routes.each do |route|
109
+ route_obj = OpenStruct.new(id: route['route_id'], name: route['route_name'], trips: [])
110
+ directions = route['direction']
111
+ directions.each do |dir|
112
+ trips = dir['trip']
113
+ trips.each do |trip|
114
+ route_obj.trips << OpenStruct.new(id: trip['trip_id'],
115
+ time: trip['pre_away'])
116
+ end
117
+ end
118
+
119
+ @predictions << route_obj
120
+ end
121
+ end
122
+ @predictions
123
+ end
124
+
105
125
  end
106
126
  end
107
127
 
@@ -1,3 +1,3 @@
1
1
  module MBTARealtime
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
@@ -2,11 +2,11 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: mbta-realtime 0.1.2 ruby lib
5
+ # stub: mbta-realtime 0.1.3 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "mbta-realtime"
9
- s.version = "0.1.2"
9
+ s.version = "0.1.3"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mbta-realtime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Cloyd