ratis 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,58 +2,50 @@ module Ratis
2
2
 
3
3
  class NextBus
4
4
 
5
- attr_accessor :stops, :runs
6
-
7
- # Initializes a NextBus object with stops and runs.
8
- # @return [NextBus]
9
- #
10
- # == Parameters:
11
- #
12
- # [stops] <em>Optional</em> -
13
- # An array of stops. Defaults to empty array.
14
- # [runs] <em>Optional</em> -
15
- # An array of runs. Defaults to empty array.
16
-
17
- def initialize(_stops = [], _runs = [])
18
- @stops, @runs = _stops, _runs
19
- end
5
+ attr_accessor :runs, :status, :sign, :routetype, :times, :direction
6
+
7
+ def initialize(service, _runs = [])
8
+ @runs = _runs
20
9
 
21
- # Returns results of NextBus query containing arrays of stops and runs.
22
- # @return [NextBus] containing next buses.
23
- #
24
- # == Parameters:
25
- #
26
- # Takes hash of conditions
27
- #
28
- # [option1] <b>Required</b> -
29
- # Description of required param
30
- # [option2] <em>Optional</em> -
31
- # Description of optional param
32
- # [option3] <em>Optional</em> -
33
- # Description of optional param
34
- # [option4] <em>Optional</em> -
35
- # Description of optional param
10
+ @status = service[:status]
11
+ @sign = service[:sign]
12
+ @routetype = service[:routetype]
13
+ @times = service[:times]
14
+ @direction = service[:direction]
15
+ end
36
16
 
37
17
  def self.where(conditions)
38
- stop_id = conditions.delete :stop_id
39
- app_id = conditions.delete(:app_id) || 'na'
18
+ stop_id = conditions.delete(:stop_id)
19
+ app_id = conditions.delete(:app_id) || 'ratis-specs'
20
+ type = conditions.delete(:type) || 'N' # N for Next Bus
21
+
22
+ if datetime = conditions.delete(:datetime)
23
+ raise ArgumentError.new('If datetime supplied it should be a Time or DateTime instance, otherwise it defaults to Time.now') unless datetime.is_a?(DateTime) || datetime.is_a?(Time)
24
+ else
25
+ datetime = Time.now
26
+ end
40
27
 
41
28
  raise ArgumentError.new('You must provide a stop ID') unless stop_id
29
+
42
30
  Ratis.all_conditions_used? conditions
43
31
 
44
- response = Request.get 'Nextbus2', { 'Stopid' => stop_id, 'Appid' => app_id }
32
+ response = Request.get 'Nextbus', {'Stopid' => stop_id,
33
+ 'Appid' => app_id,
34
+ 'Date' => datetime.strftime("%m/%d/%Y"),
35
+ 'Time' => datetime.strftime("%I%M"),
36
+ 'Type' => type }
45
37
  return [] unless response.success?
46
38
 
47
- stops = response.to_array :nextbus2_response, :stops, :stop
48
- runs = response.to_array :nextbus2_response, :runs, :run
49
-
50
- NextBus.new stops, runs
39
+ service = response.body[:nextbus_response][:atstop][:service]
40
+ runs = response.to_array :nextbus_response, :atstop, :service, :tripinfo
41
+ NextBus.new service, runs
51
42
  end
52
43
 
53
44
  # Gets description of first stop
54
45
  # @return [String] Description of first stop or nil.
55
46
 
56
47
  def first_stop_description
48
+ raise 'Not yet implemented'
57
49
  stops.first ? stops.first[:description] : nil
58
50
  end
59
51
 
@@ -61,6 +53,7 @@ module Ratis
61
53
  # @return [Hash] NextBus details in a hash.
62
54
 
63
55
  def to_hash
56
+ raise 'Not yet implemented'
64
57
  { :stopname => first_stop_description,
65
58
  :signs => runs.map { |run| run[:sign] }.uniq,
66
59
  :runs => runs.map do |run|
@@ -77,6 +70,7 @@ module Ratis
77
70
  # @private
78
71
 
79
72
  def to_hash_for_xml
73
+ raise 'Not yet implemented'
80
74
  { :stopname => first_stop_description,
81
75
  :runs => runs.map do |run|
82
76
  { :time => run[:estimatedtime],
@@ -0,0 +1,93 @@
1
+ module Ratis
2
+
3
+ class NextBus2
4
+
5
+ attr_accessor :stops, :runs
6
+
7
+ # Initializes a NextBus object with stops and runs.
8
+ # @return [NextBus]
9
+ #
10
+ # == Parameters:
11
+ #
12
+ # [stops] <em>Optional</em> -
13
+ # An array of stops. Defaults to empty array.
14
+ # [runs] <em>Optional</em> -
15
+ # An array of runs. Defaults to empty array.
16
+
17
+ def initialize(_stops = [], _runs = [])
18
+ @stops, @runs = _stops, _runs
19
+ end
20
+
21
+ # Returns results of NextBus query containing arrays of stops and runs.
22
+ # @return [NextBus] containing next buses.
23
+ #
24
+ # == Parameters:
25
+ #
26
+ # Takes hash of conditions
27
+ #
28
+ # [option1] <b>Required</b> -
29
+ # Description of required param
30
+ # [option2] <em>Optional</em> -
31
+ # Description of optional param
32
+ # [option3] <em>Optional</em> -
33
+ # Description of optional param
34
+ # [option4] <em>Optional</em> -
35
+ # Description of optional param
36
+
37
+ def self.where(conditions)
38
+ stop_id = conditions.delete :stop_id
39
+ app_id = conditions.delete(:app_id) || 'na'
40
+
41
+ raise ArgumentError.new('You must provide a stop ID') unless stop_id
42
+ Ratis.all_conditions_used? conditions
43
+
44
+ response = Request.get 'Nextbus2', { 'Stopid' => stop_id, 'Appid' => app_id }
45
+ return [] unless response.success?
46
+ debugger
47
+ stops = response.to_array :nextbus2_response, :stops, :stop
48
+ runs = response.to_array :nextbus2_response, :runs, :run
49
+
50
+ NextBus.new stops, runs
51
+ end
52
+
53
+ # Gets description of first stop
54
+ # @return [String] Description of first stop or nil.
55
+
56
+ def first_stop_description
57
+ stops.first ? stops.first[:description] : nil
58
+ end
59
+
60
+ # Details of NextBus instance in a hash.
61
+ # @return [Hash] NextBus details in a hash.
62
+
63
+ def to_hash
64
+ { :stopname => first_stop_description,
65
+ :signs => runs.map { |run| run[:sign] }.uniq,
66
+ :runs => runs.map do |run|
67
+ { :time => run[:estimatedtime],
68
+ :sign => run[:sign],
69
+ :adherence => run[:adherence],
70
+ :route => run[:route]
71
+ }
72
+ end
73
+ }
74
+ end
75
+
76
+ # Details of NextBus instance in a hash to be transformed to xml
77
+ # @private
78
+
79
+ def to_hash_for_xml
80
+ { :stopname => first_stop_description,
81
+ :runs => runs.map do |run|
82
+ { :time => run[:estimatedtime],
83
+ :scheduled_time => run[:triptime],
84
+ :sign => run[:sign],
85
+ :adherence => run[:adherence],
86
+ :route => run[:route]
87
+ }
88
+ end
89
+ }
90
+ end
91
+ end
92
+
93
+ end
data/lib/ratis/version.rb CHANGED
@@ -5,7 +5,7 @@ module Ratis
5
5
  def version
6
6
  @version ||= begin
7
7
 
8
- string = '3.0.0'
8
+ string = '3.1.0'
9
9
 
10
10
  def string.parts
11
11
  split('.').map { |p| p.to_i }
data/lib/ratis.rb CHANGED
@@ -9,6 +9,7 @@ require 'ratis/landmark'
9
9
  require 'ratis/landmark_category'
10
10
  require 'ratis/location'
11
11
  require 'ratis/next_bus'
12
+ require 'ratis/next_bus2'
12
13
  require 'ratis/pattern'
13
14
  require 'ratis/pattern/routeinfo'
14
15
  require 'ratis/point_2_point'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ratis
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 3
8
+ - 1
8
9
  - 0
9
- - 0
10
- version: 3.0.0
10
+ version: 3.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Burst Software
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-05-15 00:00:00 Z
18
+ date: 2013-06-06 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: savon
@@ -190,6 +190,34 @@ dependencies:
190
190
  version: "0"
191
191
  type: :development
192
192
  version_requirements: *id012
193
+ - !ruby/object:Gem::Dependency
194
+ name: rspec-instafail
195
+ prerelease: false
196
+ requirement: &id013 !ruby/object:Gem::Requirement
197
+ none: false
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ hash: 3
202
+ segments:
203
+ - 0
204
+ version: "0"
205
+ type: :development
206
+ version_requirements: *id013
207
+ - !ruby/object:Gem::Dependency
208
+ name: chronic
209
+ prerelease: false
210
+ requirement: &id014 !ruby/object:Gem::Requirement
211
+ none: false
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ hash: 3
216
+ segments:
217
+ - 0
218
+ version: "0"
219
+ type: :development
220
+ version_requirements: *id014
193
221
  description:
194
222
  email: irish@burstdev.com
195
223
  executables: []
@@ -209,6 +237,7 @@ files:
209
237
  - lib/ratis/landmark_category.rb
210
238
  - lib/ratis/location.rb
211
239
  - lib/ratis/next_bus.rb
240
+ - lib/ratis/next_bus2.rb
212
241
  - lib/ratis/pattern/routeinfo.rb
213
242
  - lib/ratis/pattern.rb
214
243
  - lib/ratis/point_2_point/group.rb