cumtd 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cumtd.rb +28 -2
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 94f031a775a83336a3b53c5f9467c031fbe3906b
4
- data.tar.gz: b22b5af9fa439244773f77b2da7011f0da29c517
3
+ metadata.gz: b9b29b282253fd7d5f524f61e7e65092e0421018
4
+ data.tar.gz: c0b228e68084015682b7a547aabb5a4d8bafa92f
5
5
  SHA512:
6
- metadata.gz: b00db28c5b8d597e65129b982e91f33738a14a62eb6575ae266cdb7be3625673bae7262e673a9478d836eed7c829732bd92c7d086cab978a367a9764735d0e05
7
- data.tar.gz: 29ecdbfbab97529a877f013184bbe657d29cb5d7c7174a7670d783b13ba5e36198a476f51708ed1ea506c4165fec9c903adcd6bd18846c7196758ffb318ff270
6
+ metadata.gz: 4a6c9f5aebe2c84db2176df6641c377f6fe3736f46632c0266a240bf11c8679c7991e64c3b460cbffcc51bf905ae0d46507b98a373541d2d0bcbe5cc639babfa
7
+ data.tar.gz: 2ad657f57f944cdeb8e9705cf755250cc8d96b2841dada811b2765f465492a91602f918e2459c8266a26fd527962612462ddca0fa57e6d47cdecea48903705af
@@ -10,8 +10,13 @@ class CUMTD
10
10
  @api_key
11
11
  end
12
12
 
13
- def get_stops(lat, lon)
14
- response = self.class.get("/GetStopsByLatLon?key=#{api_key}&lat=#{lat}&lon=#{lon}")
13
+ def current_stops
14
+ @current_stops
15
+ end
16
+
17
+ def get_stops(lat, lon, count=20)
18
+ response = self.class.get("/GetStopsByLatLon?key=#{api_key}&lat=#{lat}&lon=#{lon}&count=#{count}")
19
+ current_stops = response["stops"]
15
20
  return stops = response["stops"]
16
21
  end
17
22
 
@@ -28,6 +33,11 @@ class CUMTD
28
33
  return response.parsed_response["routes"]
29
34
  end
30
35
 
36
+ def get_stop_by_id(stop_id)
37
+ response = self.class.get("/GetStop?key=#{api_key}&stop_id=#{stop_id}")
38
+ return response.parsed_response["stops"].first["stop_name"]
39
+ end
40
+
31
41
  def get_departures_by_stop(stop_id)
32
42
  response = self.class.get("/GetDeparturesByStop?key=#{api_key}&stop_id=#{stop_id}")
33
43
  return departures = response.parsed_response["departures"]
@@ -40,4 +50,20 @@ class CUMTD
40
50
  end
41
51
  end
42
52
 
53
+ # Returns an array of hashes. Each hash contains a "stop" key denoting the stop
54
+ # and the "departures" key contains one departure. These hashes are sorted
55
+ # based on length of time until they depart, given stops to get departures for.
56
+
57
+ def nearest_departures(stops)
58
+ master_deps = Array.new
59
+ stops.each do |stop|
60
+ # master_deps.concat(Hash["stop", stop, "departures", get_departures_by_stop(stop["stop_id"]))
61
+ stops_from_deps = get_departures_by_stop(stop["stop_id"])
62
+ stops_from_deps.each do |stop_dep|
63
+ master_deps << Hash["stop", stop, "departures", stop_dep]
64
+ end
65
+ end
66
+ return master_deps.sort_by! { |stop| stop["departures"]["expected_mins"] }
67
+ end
68
+
43
69
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cumtd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Jackson