octranspo_fetch 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/octranspo_fetch.rb +13 -2
  2. metadata +2 -2
@@ -54,7 +54,6 @@ class OCTranspo
54
54
  @cache_hits += 1
55
55
  return cached_result[:route_summary]
56
56
  end
57
-
58
57
  @cache_misses += 1
59
58
 
60
59
  xresult = fetch "GetRouteSummaryForStop", "stopNo=#{stop}"
@@ -155,7 +154,7 @@ class OCTranspo
155
154
 
156
155
  # Sometimes OC Transpo doesn't return any data for a route, even though it should. When
157
156
  # this happens, if we have cached data, we use that, even if it's slightly stale.
158
- if !found_data and !cached_result.nil?
157
+ if !found_data and !cached_result.nil? and (get_trip_count(cached_result[:next_trips]) > 0)
159
158
  # Use the cached data, even if it's stale
160
159
  result = adjust_cached_trip_times(cached_result[:next_trips])
161
160
  else
@@ -241,6 +240,18 @@ class OCTranspo
241
240
  return xresult
242
241
  end
243
242
 
243
+ # Count the number of trips in a result from OC Transpo
244
+ def get_trip_count(routes)
245
+ answer = 0
246
+ if !routes.nil?
247
+ routes[:routes].each do |route|
248
+ answer += route[:trips].length
249
+ end
250
+ end
251
+
252
+ return answer
253
+ end
254
+
244
255
  # Return a single child from a nokogiri document.
245
256
  def get_child(node, el)
246
257
  return node.at_xpath(el, OCT_NS)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octranspo_fetch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-23 00:00:00.000000000 Z
12
+ date: 2013-09-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri