ierail 0.3.2 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- M2ZmNzc1ZDRiZGIwMjkzZDc2Mjc1N2Y4MDM1MDhjNGZjMTRiNGFmZA==
4
+ M2I4ZmZhZmU5MDM4N2Y0YzQyYTIxZDFjMTFmOWYxZDEyMzkyNmQ2Yg==
5
5
  data.tar.gz: !binary |-
6
- Y2I0NWVhZDU0M2E3YTAwMWNjOTc2YmJlYzNhMDVmMjc4YzM3MTZlOA==
6
+ OGZhZTJjMDA5NzQ4NjhhOWVjZGM3NTc3YjgyOTFiZTdhOGVlNGI0ZQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NjkwOWVmNTE2YzQ3NTEzZTQ0ZDhlNTliYzdmYWM1M2MyYjFjNDZjNTM2MDQy
10
- OWRlYzFkZGMxZWY3NTRmYTU0ZWNmYTc3OGExNGZiNzIxNTY2YjBiYjk4ZDBj
11
- NDJjMDg1NjM4N2IwODBlNjcwNDE5YjM2OTAzYmI0Y2EyMDM5ZTU=
9
+ ZjQ1NjY0NmVmY2QxMmE2MjcwZmE0ZjIxYjAzMmM4ZTA3NTY1MDI5MGQ4ODlj
10
+ MDljZGFkZTcwMTkyMzgzNDVlNjkxYTQ0YTZhMTE3NzQwMTQ4NjViNWE4MWFk
11
+ NTQxMDQzMmI1ZDQyYjMwM2M3NDQzNjZhNWJmZDRlMDRjM2ZlY2E=
12
12
  data.tar.gz: !binary |-
13
- ZTg1OTI0NTdiMmU1MGEzMzk5NmI0YjM3NTlhMDMzNjlhYzIwM2M2ZTFmMWMz
14
- ZTE3MTA1YWJiZjAxNTRmNDhhZGU5MGQ0MWRmNjUzOWUxMDBlOWI0YjczOGMx
15
- ZjcxYmZhMzFmZGY1ZDdlYWZhZGJmNTYxYjgxZTRhOTg2MTdjNTQ=
13
+ ZDIzZjI2MTA3Y2M1ZThkYzNhOWVkNWQ2YTFjY2VmMjcwNmJlZmJlOTc0M2Zi
14
+ NzQwYzY3ZTA2NWFlZWUyZDE5NjY4MmI0ZDAwMmU1ZGQ5MDQ2NmFlNDBiNDVl
15
+ ZGRmNTgwNmVmNDE5MDE0NWEwNGYwNDMxYTFiOWIyODUyZDhmOWE=
data/Gemfile.lock CHANGED
@@ -1,10 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ierail (0.3)
4
+ ierail (0.3.3)
5
5
  json (~> 1.7.7)
6
6
  nokogiri (~> 1.5.0)
7
7
  rest-client (~> 1.6.7)
8
+ tzinfo (~> 0.3.37)
8
9
 
9
10
  GEM
10
11
  remote: https://rubygems.org/
@@ -28,6 +29,7 @@ GEM
28
29
  simplecov-html (~> 0.7.1)
29
30
  simplecov-html (0.7.1)
30
31
  thor (0.18.1)
32
+ tzinfo (0.3.37)
31
33
 
32
34
  PLATFORMS
33
35
  ruby
data/ierail.gemspec CHANGED
@@ -1,6 +1,8 @@
1
+ require 'date'
2
+
1
3
  Gem::Specification.new do |s|
2
4
  s.name = 'ierail'
3
- s.version = '0.3.2'
5
+ s.version = '0.3.4'
4
6
  s.date = Date.today.to_s
5
7
  s.summary = "Irish Rail Train Schedule and Status API"
6
8
  s.description = "Irish Rail Train Schedule and Status API"
@@ -11,4 +13,5 @@ Gem::Specification.new do |s|
11
13
  s.add_dependency 'nokogiri', '~> 1.5.0'
12
14
  s.add_dependency 'rest-client', '~> 1.6.7'
13
15
  s.add_dependency 'json', '~> 1.7.7'
16
+ s.add_dependency 'tzinfo', '~> 0.3.37'
14
17
  end
data/lib/core_ext.rb CHANGED
@@ -2,20 +2,21 @@ class Array
2
2
  #Filters elements, collecting those
3
3
  #whose times are before _time_
4
4
  def before time
5
- select {|t| Time.parse(t.expdepart) <= Time.parse(time) }
5
+ select {|t| t.expdepart <= Time.parse(time) }
6
6
  end
7
7
 
8
8
  #Filters elements, collecting those
9
9
  #whose times are after _time_
10
10
  def after time
11
- select {|t| Time.parse(t.expdepart) >= Time.parse(time) }
11
+ select {|t| t.expdepart >= Time.parse(time) }
12
12
  end
13
13
 
14
14
  # The 'in' is just sugar really, saving the
15
15
  # programmer from doing a trivial computation
16
16
  # over and over again in their code.
17
17
  def in time
18
- future_time = Time.now + (time * 60)
19
- before "#{future_time.hour}:#{future_time.min}"
18
+ select { |t|
19
+ ((t.expdepart - t.query_time ) / 60) < time
20
+ }
20
21
  end
21
22
  end
data/lib/station_data.rb CHANGED
@@ -8,20 +8,20 @@ class StationData
8
8
  @traincode = hash['Traincode']
9
9
  @station_name = hash['Stationfullname']
10
10
  @station_code = hash['Stationcode']
11
- @query_time = hash['Querytime']
11
+ @query_time = Time.parse(hash['Querytime'])
12
12
  @train_date = hash['Traindate']
13
13
  @origin = hash['Origin']
14
14
  @destination = hash['Destination']
15
- @origin_time = hash['Origintime']
16
- @destination_time = hash['Destinationtime']
15
+ @origin_time = Time.parse hash['Origintime']
16
+ @destination_time = Time.parse hash['Destinationtime']
17
17
  @status = hash['Status']
18
18
  @last_location = hash['Lastlocation']
19
19
  @duein = hash['Duein']
20
20
  @late = hash['Late']
21
- @exparrival = hash['Exparrival']
22
- @expdepart = hash['Expdepart']
23
- @scharrival = hash['Scharrival']
24
- @schdepart = hash['Schdepart']
21
+ @exparrival = Time.parse hash['Exparrival']
22
+ @expdepart = Time.parse hash['Expdepart']
23
+ @scharrival = Time.parse hash['Scharrival']
24
+ @schdepart = Time.parse hash['Schdepart']
25
25
  @direction = hash['Direction']
26
26
  @train_type = hash['Traintype']
27
27
  end
data/test/unit/ierail.rb CHANGED
@@ -4,10 +4,21 @@ require_relative 'helper'
4
4
 
5
5
  require 'minitest/autorun'
6
6
  require 'ierail'
7
+ require 'tzinfo'
7
8
 
8
9
  class IERailTest < MiniTest::Unit::TestCase
9
10
  def setup
10
11
  @ir = IERail.new
12
+
13
+ @now = Time.now
14
+
15
+ if TZInfo::Timezone.get('Europe/Dublin').current_period.dst?
16
+ unless @now.zone == 'IST'
17
+ @now -= @now.utc_offset - 3600
18
+ end
19
+ else
20
+ @now -= @now.utc_offset
21
+ end
11
22
  end
12
23
 
13
24
  def test_that_the_train_directions_are_correct
@@ -24,23 +35,23 @@ class IERailTest < MiniTest::Unit::TestCase
24
35
 
25
36
  def test_that_the_before_time_constraint_works
26
37
  #Thirty minutes from now
27
- thirty_mins = Time.now + 60*30
38
+ thirty_mins = @now + (60 * 30)
28
39
  time = "#{thirty_mins.hour}:#{thirty_mins.min}" # "HH:MM"
29
40
  before_train = @ir.southbound_from('Malahide').before(time).sample
30
- assert Time.parse(before_train.expdepart) <= thirty_mins
41
+ assert before_train.expdepart <= thirty_mins
31
42
  end
32
43
 
33
44
  def test_that_the_after_time_constraint_works
34
45
  #Thirty minutes from now
35
- thirty_mins = Time.now + 60*30
46
+ thirty_mins = @now + (60 * 30)
36
47
  time = "#{thirty_mins.hour}:#{thirty_mins.min}" # "HH:MM"
37
48
  after_train = @ir.southbound_from('Malahide').after(time).sample
38
- assert Time.parse(after_train.expdepart) >= thirty_mins
49
+ assert after_train.expdepart >= thirty_mins
39
50
  end
40
51
 
41
52
  def test_that_the_in_constraint_works
42
53
  mins = 30
43
- thirty_mins = Time.now + 60 * mins
54
+ thirty_mins = @now + (60 * mins)
44
55
  time = "#{thirty_mins.hour}:#{thirty_mins.min}" # "HH:MM"
45
56
  before_train = @ir.southbound_from('Malahide').before(time)
46
57
 
@@ -33,7 +33,7 @@ class StationDataTest < MiniTest::Unit::TestCase
33
33
  end
34
34
 
35
35
  def test_that_there_is_a_query_time
36
- refute_empty @station_data.query_time
36
+ refute_nil @station_data.query_time
37
37
  end
38
38
 
39
39
  def test_that_there_is_a_train_date
@@ -46,7 +46,7 @@ class StationDataTest < MiniTest::Unit::TestCase
46
46
 
47
47
  def test_that_there_is_an_origin_name_and_time
48
48
  refute_empty @station_data.origin[:name]
49
- refute_empty @station_data.origin[:time]
49
+ refute_nil @station_data.origin[:time]
50
50
  end
51
51
 
52
52
  def test_that_destination_method_returns_a_hash
@@ -55,7 +55,7 @@ class StationDataTest < MiniTest::Unit::TestCase
55
55
 
56
56
  def test_that_there_is_a_destination_name_and_time
57
57
  refute_empty @station_data.destination[:name]
58
- refute_empty @station_data.destination[:time]
58
+ refute_nil @station_data.destination[:time]
59
59
  end
60
60
 
61
61
  def test_that_arrival_method_returns_a_hash
@@ -63,8 +63,8 @@ class StationDataTest < MiniTest::Unit::TestCase
63
63
  end
64
64
 
65
65
  def test_that_there_is_an_arrival_sched_and_exp
66
- refute_empty @station_data.arrival[:scheduled]
67
- refute_empty @station_data.arrival[:expected]
66
+ refute_nil @station_data.arrival[:scheduled]
67
+ refute_nil @station_data.arrival[:expected]
68
68
  end
69
69
 
70
70
  def test_that_departure_method_returns_a_hash
@@ -72,8 +72,8 @@ class StationDataTest < MiniTest::Unit::TestCase
72
72
  end
73
73
 
74
74
  def test_that_there_is_a_departure_sched_and_exp
75
- refute_empty @station_data.departure[:scheduled]
76
- refute_empty @station_data.departure[:expected]
75
+ refute_nil @station_data.departure[:scheduled]
76
+ refute_nil @station_data.departure[:expected]
77
77
  end
78
78
 
79
79
  def test_that_it_responds_to_late?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ierail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oisin Hurley
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-10 00:00:00.000000000 Z
12
+ date: 2013-05-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -53,6 +53,20 @@ dependencies:
53
53
  - - ~>
54
54
  - !ruby/object:Gem::Version
55
55
  version: 1.7.7
56
+ - !ruby/object:Gem::Dependency
57
+ name: tzinfo
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: 0.3.37
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 0.3.37
56
70
  description: Irish Rail Train Schedule and Status API
57
71
  email: oi.sin@nis.io
58
72
  executables: []