Class: Ratis::NextBus2
- Inherits:
-
Object
- Object
- Ratis::NextBus2
- Defined in:
- lib/ratis/next_bus2.rb
Instance Attribute Summary collapse
-
#runs ⇒ Object
Returns the value of attribute runs.
-
#stops ⇒ Object
Returns the value of attribute stops.
Class Method Summary collapse
-
.where(conditions) ⇒ NextBus
Returns results of NextBus query containing arrays of stops and runs.
Instance Method Summary collapse
-
#first_stop_description ⇒ String
Gets description of first stop.
-
#initialize(_stops = [], _runs = []) ⇒ NextBus
constructor
Initializes a NextBus object with stops and runs.
-
#to_hash ⇒ Hash
Details of NextBus instance in a hash.
-
#to_hash_for_xml ⇒ Object
Details of NextBus instance in a hash to be transformed to xml.
Constructor Details
#initialize(_stops = [], _runs = []) ⇒ NextBus
Initializes a NextBus object with stops and runs.
Parameters:
- stops
-
Optional - An array of stops. Defaults to empty array.
- runs
-
Optional - An array of runs. Defaults to empty array.
17 18 19 |
# File 'lib/ratis/next_bus2.rb', line 17 def initialize(_stops = [], _runs = []) @stops, @runs = _stops, _runs end |
Instance Attribute Details
#runs ⇒ Object
Returns the value of attribute runs.
5 6 7 |
# File 'lib/ratis/next_bus2.rb', line 5 def runs @runs end |
#stops ⇒ Object
Returns the value of attribute stops.
5 6 7 |
# File 'lib/ratis/next_bus2.rb', line 5 def stops @stops end |
Class Method Details
.where(conditions) ⇒ NextBus
Returns results of NextBus query containing arrays of stops and runs.
Parameters:
Takes hash of conditions
- option1
-
Required - Description of required param
- option2
-
Optional - Description of optional param
- option3
-
Optional - Description of optional param
- option4
-
Optional - Description of optional param
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ratis/next_bus2.rb', line 37 def self.where(conditions) stop_id = conditions.delete :stop_id app_id = conditions.delete(:app_id) || 'ratis-gem' raise ArgumentError.new('You must provide a stop ID') unless stop_id Ratis.all_conditions_used? conditions response = Request.get 'Nextbus2', { 'Stopid' => stop_id, 'Appid' => app_id } return [] unless response.success? debugger stops = response.to_array :nextbus2_response, :stops, :stop runs = response.to_array :nextbus2_response, :runs, :run NextBus.new stops, runs end |
Instance Method Details
#first_stop_description ⇒ String
Gets description of first stop
56 57 58 59 |
# File 'lib/ratis/next_bus2.rb', line 56 def first_stop_description raise 'Not yet implemented' stops.first ? stops.first[:description] : nil end |
#to_hash ⇒ Hash
Details of NextBus instance in a hash.
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/ratis/next_bus2.rb', line 64 def to_hash raise 'Not yet implemented' { :stopname => first_stop_description, :signs => runs.map { |run| run[:sign] }.uniq, :runs => runs.map do |run| { :time => run[:estimatedtime], :sign => run[:sign], :adherence => run[:adherence], :route => run[:route] } end } end |
#to_hash_for_xml ⇒ Object
Details of NextBus instance in a hash to be transformed to xml
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/ratis/next_bus2.rb', line 81 def to_hash_for_xml raise 'Not yet implemented' { :stopname => first_stop_description, :runs => runs.map do |run| { :time => run[:estimatedtime], :scheduled_time => run[:triptime], :sign => run[:sign], :adherence => run[:adherence], :route => run[:route] } end } end |