Class: TripSpark::Client::Routes

Inherits:
API
  • Object
show all
Extended by:
Memoist
Defined in:
lib/tripspark_api/client/routes.rb

Instance Method Summary collapse

Methods inherited from API

#get_request, include_api, #post_request, #refresh, require_all, singleton

Methods included from TripSpark::Connection

#adapter, #connection, #register_adapter

Instance Method Details

#get(key) ⇒ Object Also known as: find

Return the route whose key matches the given key



13
14
15
# File 'lib/tripspark_api/client/routes.rb', line 13

def get key
  list.find{ |route| route.key == key }
end

#listObject Also known as: all

Return a list of all routes on the system.



6
7
8
# File 'lib/tripspark_api/client/routes.rb', line 6

def list
  post_request('/RouteMap/GetRoutes/').map{ |route| Route.new(route) }
end

#route_direction_pairs(*routes) ⇒ Object

Return a list of pairs of route keys and direction keys. Used when requesting vehicles.



21
22
23
24
25
26
27
28
# File 'lib/tripspark_api/client/routes.rb', line 21

def route_direction_pairs *routes
  list.each_with_object([]) do |route, pairs|
    next unless routes.empty? or !routes.include?(route.key)
    route.patterns.each do |pattern|
      pairs << [route.key, pattern.direction.key]
    end
  end.uniq
end