easy_transilien 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d0f3e75eec981ffaa1bcb9eb609904855e53fabf
4
- data.tar.gz: f43ece58c36e86416f8c277e8342d2949a2d0000
3
+ metadata.gz: d12ffd1f3e0145b33f28cd3680ca70cd5521fde5
4
+ data.tar.gz: ee92491d951b7ae3d6adb4e4f57a124f7049d595
5
5
  SHA512:
6
- metadata.gz: 0db76307217b2cef514905c2bcc95211cce4bc53276e3487738de7d4d57ed60e55fca852709696e2895685d78c85b177145c72f99c81d826edd83001fbab012d
7
- data.tar.gz: 63c81f059d66998e0ebe909d9e22c36d4a49461112488666034bffc60c15858a3516e347526754b446dab201c90e7c8524038b46fa01d9236b9e5ac63fa1c784
6
+ metadata.gz: 96da7dbe73c2eb63f419cce03b2a0f96513d2b3c5fc790e67c159cdae7e554777a32faa72f5057b88a1af5c57eb381b09416211928a98c567d1c060e5cb34632
7
+ data.tar.gz: 1bbe280e4d3cb89e3dab4b2ca0212233078321c92541f6087dddfff7c7a6500d216d289b6972309df37ac73c2d671d410ec2c4b6c333456226bedae0af4cbb81
data/CHANGELOG ADDED
@@ -0,0 +1,5 @@
1
+ 0.0.5:
2
+ * Handle options[:at] and options[:last] as promise by the doc
3
+ * Add Trip#last to be consitant
4
+ * Trip#find auto correct when at is after last
5
+ * TripSpec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- easy_transilien (0.0.3)
4
+ easy_transilien (0.0.5)
5
5
  transilien_microservices (~> 0.0.6)
6
6
 
7
7
  GEM
@@ -11,8 +11,8 @@ GEM
11
11
  timers (~> 1.1.0)
12
12
  coderay (1.1.0)
13
13
  diff-lcs (1.2.5)
14
- faraday (0.8.8)
15
- multipart-post (~> 1.2.0)
14
+ faraday (0.9.0)
15
+ multipart-post (>= 1.2, < 3)
16
16
  ffi (1.9.3)
17
17
  formatador (0.2.4)
18
18
  guard (2.2.5)
@@ -31,7 +31,7 @@ GEM
31
31
  lumberjack (1.0.4)
32
32
  method_source (0.8.2)
33
33
  mini_portile (0.5.2)
34
- multipart-post (1.2.0)
34
+ multipart-post (2.0.0)
35
35
  nokogiri (1.6.1)
36
36
  mini_portile (~> 0.5.0)
37
37
  pry (0.9.12.4)
@@ -14,7 +14,7 @@ module EasyTransilien
14
14
  attr_accessor :mission
15
15
  attr_accessor :ms_journey
16
16
 
17
- attr_accessor :at
17
+ attr_accessor :at, :last # boundaries given via #find options
18
18
  attr_accessor :stops
19
19
 
20
20
  class << self
@@ -22,15 +22,20 @@ module EasyTransilien
22
22
  # Find
23
23
  # Options:
24
24
  # * at (default Time.new)
25
- # * last (default at + 3600)
25
+ # * last (default at + default_duration(3600))
26
26
  # * whole_day: if true, override at and last with respectively 00:01 and 00:00
27
27
  # * return: if true, invert from and to
28
28
  def find(from, to , options= {})
29
29
  at = last = nil
30
+ default_duration = 3600
30
31
  if options[:whole_day]
31
32
  now = Time.new
32
33
  at = Time.new(now.year, now.month, now.day, 0, 0, 1)
33
34
  last = at + 86400
35
+ elsif options[:at] && options[:at].is_a?(Time)
36
+ at = options[:at]
37
+ last = options[:last] if options[:last] && options[:last].is_a?(Time)
38
+ last ||= at + default_duration
34
39
  end
35
40
  if options[:return]
36
41
  from_was = from
@@ -39,9 +44,16 @@ module EasyTransilien
39
44
  end
40
45
  at ||= Time.new
41
46
  raise "at params MUST be a valid Time instance. Given: #{at.inspect}" unless at.is_a?(Time)
42
- last ||= at + 3600
47
+ last ||= at + default_duration
43
48
  raise "last params MUST be a valid Time instance. Given: #{last.inspect}" unless last.is_a?(Time)
44
49
 
50
+ # auto sort the mess… Yes, I'm very kind to these people
51
+ if at > last
52
+ aat = at
53
+ at = last
54
+ last = aat
55
+ end
56
+
45
57
  from_station = Station.find(from).first
46
58
  to_station = Station.find(to).first
47
59
 
@@ -56,6 +68,7 @@ module EasyTransilien
56
68
  journeys.each do |journey|
57
69
  item = new
58
70
  item.at = at
71
+ item.last = last
59
72
  item.from_station = from_station
60
73
  item.to_station = to_station
61
74
  item.stops = journey.stops.map do |ms_stop|
@@ -1,3 +1,3 @@
1
1
  module EasyTransilien
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/spec/trip_spec.rb CHANGED
@@ -8,4 +8,43 @@ describe EasyTransilien::Trip do
8
8
  trips = EasyTransilien::Trip.find('val d\'argenteuil', 'paris saint-lazare')
9
9
  trips.first.is_a?(EasyTransilien::Trip).should be_true
10
10
  end
11
+
12
+ it 'should accepts options[:at] and handle last at default_duration' do
13
+ at = Time.now
14
+ trips = EasyTransilien::Trip.find('val d\'argenteuil', 'paris saint-lazare', {at: at})
15
+ trips.first.at.should eql(at)
16
+ trips.first.last.should eql(at + 3600)
17
+ end
18
+
19
+ it 'should accepts options[:at] AND options[:last] at the same time' do
20
+ at = Time.now
21
+ last = Time.now + 3600 * 2 + 42 # arbitrary…
22
+ trips = EasyTransilien::Trip.find('val d\'argenteuil', 'paris saint-lazare', {at: at, last: last})
23
+ trips.first.at.should eql(at)
24
+ trips.first.last.should eql(last)
25
+ end
26
+
27
+ it 'should auto sort when at is after last' do
28
+ last = Time.now
29
+ at = Time.now + 3600 * 2 + 42 # arbitrary…
30
+ trips = EasyTransilien::Trip.find('val d\'argenteuil', 'paris saint-lazare', {at: at, last: last})
31
+ trips.first.at.should eql(last)
32
+ trips.first.last.should eql(at)
33
+ end
34
+
35
+ it 'should autoset at and last for options[:whole_day]' do
36
+ hoy = Time.new
37
+ trips = EasyTransilien::Trip.find('val d\'argenteuil', 'paris saint-lazare', {whole_day: true})
38
+ trips.first.at.should eql(Time.new(hoy.year, hoy.month, hoy.day, 0, 0, 1))
39
+ trips.first.last.should eql(Time.new(hoy.year, hoy.month, (hoy.day + 1)) + 1)
40
+ end
41
+
42
+ it 'should ignore options :at and :last when :whole_day is set' do
43
+ hoy = Time.new
44
+ at = Time.now
45
+ last = Time.now + 3600 * 2 + 42 # arbitrary…
46
+ trips = EasyTransilien::Trip.find('val d\'argenteuil', 'paris saint-lazare', {whole_day: true, at: at, last: last})
47
+ trips.first.at.should eql(Time.new(hoy.year, hoy.month, hoy.day, 0, 0, 1))
48
+ trips.first.last.should eql(Time.new(hoy.year, hoy.month, (hoy.day + 1)) + 1)
49
+ end
11
50
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_transilien
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Lecavelier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-10 00:00:00.000000000 Z
11
+ date: 2014-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: transilien_microservices
@@ -35,6 +35,7 @@ files:
35
35
  - .gitignore
36
36
  - .rspec
37
37
  - .ruby-version
38
+ - CHANGELOG
38
39
  - Gemfile
39
40
  - Gemfile.lock
40
41
  - Guardfile