Class: Ratis::Routes

Inherits:
Object
  • Object
show all
Defined in:
lib/ratis/route.rb,
lib/ratis/routes.rb

Class Method Summary collapse

Class Method Details

.allObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ratis/route.rb', line 16

def self.all
  response = Request.get 'Allroutes2'

  return [] unless response.success?

  # {:hexcolor=>"0", :route=>"0", :operator=>"AP", :description=>"0 - route", :publicroute=>"0", :hasrealtime=>"Y", :direction=>"*", :operatorname=>"VEOLIA-PHOENIX", :color=>"#000000"}
  routes = {}
  response.to_hash[:allroutes2_response][:routes][:item].each do |item|
    if routes.has_key? item[:route]
      routes[item[:route]] << item
    else
      routes[item[:route]] = [item]
    end
  end

  routes.map do |short_name, _routes|
    directions = _routes.map{|rte| rte[:direction] }.reject{|dir| dir == '*' }
    Route.new(short_name, directions)
  end.compact.sort_by{|rte| rte.short_name }
end