Class: TTC::TTCService
- Inherits:
-
Object
- Object
- TTC::TTCService
- Defined in:
- lib/ttc-gps/service.rb
Instance Method Summary collapse
Instance Method Details
#get_route(route_tag) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ttc-gps/service.rb', line 6 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 |
#get_vehicle_locations(route_tag) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ttc-gps/service.rb', line 29 def get_vehicle_locations route_tag res = {} 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 if root.elements['lastTime'] res['last_time'] = Integer(root.elements['lastTime'].attributes['time']) end end res['vehicles'] = vehicles res end |