Class: SFBATransitAPI::Route

Inherits:
Object
  • Object
show all
Defined in:
lib/sfba_transit_api/route.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#agencyObject

Returns the value of attribute agency.



3
4
5
# File 'lib/sfba_transit_api/route.rb', line 3

def agency
  @agency
end

#codeObject

Returns the value of attribute code.



3
4
5
# File 'lib/sfba_transit_api/route.rb', line 3

def code
  @code
end

#inbound_nameObject

Returns the value of attribute inbound_name.



3
4
5
# File 'lib/sfba_transit_api/route.rb', line 3

def inbound_name
  @inbound_name
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/sfba_transit_api/route.rb', line 3

def name
  @name
end

#outbound_nameObject

Returns the value of attribute outbound_name.



3
4
5
# File 'lib/sfba_transit_api/route.rb', line 3

def outbound_name
  @outbound_name
end

#stopsObject

Returns the value of attribute stops.



3
4
5
# File 'lib/sfba_transit_api/route.rb', line 3

def stops
  @stops
end

Class Method Details

.parse(agency_node, agency) ⇒ Object



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

def self.parse(agency_node, agency)
  agency_node.xpath(".//Route").map do |route_node|
    route = new


    route.agency = agency
    route.name = route_node["Name"]
    route.code = route_node["Code"]

    direction_nodes = route_node.xpath(".//RouteDirection")
    if direction_nodes.count > 0
      direction_nodes.each do |direction_node|
        if direction_node["Code"] == "Inbound"
          route.inbound_name = direction_node["Name"]
        elsif direction_node["Code"] == "Outbound"
          route.outbound_name = direction_node["Name"]
        end
      end
    end

    route.stops = Stop.parse(route_node, route)

    route
  end
end

Instance Method Details

#has_directionObject



5
6
7
# File 'lib/sfba_transit_api/route.rb', line 5

def has_direction
  not (inbound_name.nil? and outbound_name.nil?)
end

#to_sObject



9
10
11
# File 'lib/sfba_transit_api/route.rb', line 9

def to_s
  "#<SFBATransitAPI::Route:#{object_id} @name=\"#{name}\", @code=\"#{code}\", @inbound_name=\"#{inbound_name}\", @outbound_name=\"#{outbound_name}\", @agency=<SFBATransitAPI::Agency:#{agency.object_id}>, stops.count=#{stops.count}>"
end