Sha256: 8770a4d413c16be5c65a1d9d9a93f1f16d48214b9a03ef83c8a09c1b1f4009a8

Contents?: true

Size: 1.14 KB

Versions: 3

Compression:

Stored size: 1.14 KB

Contents

require 'rexml/document'
require 'open-uri'

module TTC
  class TTCService
    def get_route route_tag
      route = nil
      
      open TTC::UrlTemplates::ROUTE_CONFIG % route_tag do |file|
        config_xml = REXML::Document.new file
        
        route = Route.parse_element config_xml.root.elements['route']
        
        config_xml.root.elements.each 'route/stop' do |element|
          route.add_stop TTC::Stop::parse_element element
        end
        
        config_xml.root.elements.each 'route/direction' do |element|
          dir = element.attributes["title"].downcase!
          element.elements.each 'stop' do |element|
            route.add_stop_to_direction dir, element.attributes["tag"]
          end
        end
      end
      
      route
    end
    
    def get_vehicle_locations route_tag
      vehicles = []
      
      open TTC::UrlTemplates::STREET_CAR_LOCATIONS % route_tag do |file|
        route_xml = REXML::Document.new file
        root = route_xml.root

        root.elements.each 'vehicle' do |element|
          vehicles << TTC::Vehicle::parse_element(element)
        end
      end
      
      vehicles
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ttc-gps-0.4.0 lib/ttc-gps/service.rb
ttc-gps-0.2.0 lib/ttc-gps/service.rb
ttc-gps-0.1.0 lib/ttc-gps/service.rb