Class: Ratis::NextBus2

Inherits:
Object
  • Object
show all
Defined in:
lib/ratis/next_bus2.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#runsObject

Returns the value of attribute runs.



5
6
7
# File 'lib/ratis/next_bus2.rb', line 5

def runs
  @runs
end

#stopsObject

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

Returns:

  • (NextBus)

    containing next buses.

Raises:

  • (ArgumentError)


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_descriptionString

Gets description of first stop

Returns:

  • (String)

    Description of first stop or nil.



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_hashHash

Details of NextBus instance in a hash.

Returns:

  • (Hash)

    NextBus details 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_xmlObject

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