gasman-bahn 1.0.0 → 1.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. data/History.txt +3 -0
  2. data/lib/bahn.rb +16 -3
  3. metadata +2 -2
@@ -1,3 +1,6 @@
1
+ === 1.0.1 / 2009-05-17
2
+ * Added long hashes (Service#long_hash
3
+
1
4
  === 1.0.0 / 2009-05-17
2
5
 
3
6
  * 1 major enhancement
@@ -4,9 +4,10 @@ require 'json'
4
4
  require 'iconv'
5
5
  require 'hpricot'
6
6
  require 'cgi'
7
+ require 'digest/sha1'
7
8
 
8
9
  module Bahn
9
- VERSION = '1.0.0'
10
+ VERSION = '1.0.1'
10
11
 
11
12
  # Represents a time of day on a 24-hour clock, without implying any particular date.
12
13
  class ClockTime < Time
@@ -291,12 +292,19 @@ module Bahn
291
292
  end
292
293
 
293
294
  # Returns a hash code which will match for any two Service objects that stop at the same list of
294
- # stations at the same times. (This is the nearest thing we have to a unique ID, as Deutsche Bahn
295
- # do not expose unique IDs for services)
295
+ # stations at the same times.
296
296
  def hash
297
297
  stops.collect{|stop| stop.subhash}.hash
298
298
  end
299
299
 
300
+ # Returns a hash code which will match for any two Service objects that stop at the same list of
301
+ # stations at the same times; like hash, but using SHA1 to make it more collision-resistant.
302
+ # (This is the nearest thing we have to a unique ID, as Deutsche Bahn do not expose
303
+ # unique IDs for services)
304
+ def long_hash
305
+ Digest::SHA1.hexdigest(stops.collect{|stop| stop.long_hash_element}.join)
306
+ end
307
+
300
308
  # Returns an array of strings indicating the features of this train, as listed as 'Comments:' on
301
309
  # the Deutsche Bahn website; e.g. "Subject to compulsory reservation", "Sleeping-car". There
302
310
  # doesn't seem to be a consistent format for these.
@@ -442,6 +450,11 @@ module Bahn
442
450
  [@station.id, departure_time, arrival_time].hash
443
451
  end
444
452
 
453
+ # alternative implementation, because standard Ruby hashes are probably not collision-resistant enough
454
+ def long_hash_element # :nodoc:
455
+ "[#{@station.id},#{departure_time},#{arrival_time}]"
456
+ end
457
+
445
458
  # =====
446
459
  private
447
460
  # =====
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gasman-bahn
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Westcott
@@ -41,7 +41,7 @@ files:
41
41
  - lib/bahn.rb
42
42
  - test/test_bahn.rb
43
43
  has_rdoc: true
44
- homepage:
44
+ homepage: http://github.com/gasman/bahn/tree/master
45
45
  post_install_message:
46
46
  rdoc_options:
47
47
  - --main