Class: BusTime::BusRoute
- Inherits:
-
Object
- Object
- BusTime::BusRoute
- Defined in:
- lib/bus_time/bus_route.rb
Overview
Service bus routes handling, including direction and stop retrieval via ‘BusTime::Api`
Instance Attribute Summary collapse
- #directions ⇒ Object
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
- #stops ⇒ Object
Instance Method Summary collapse
- #display_name ⇒ Object
- #fetch_directions ⇒ Object
- #fetch_stops ⇒ Object
-
#initialize(id, name) ⇒ BusRoute
constructor
A new instance of BusRoute.
- #nearby_stops(_lat, _lon, _radius = DEFAULT_NEARBY_DISTANCE) ⇒ Object
Constructor Details
#initialize(id, name) ⇒ BusRoute
Returns a new instance of BusRoute.
10 11 12 13 |
# File 'lib/bus_time/bus_route.rb', line 10 def initialize(id, name) @id = id @name = name end |
Instance Attribute Details
#directions ⇒ Object
15 16 17 |
# File 'lib/bus_time/bus_route.rb', line 15 def directions @directions || fetch_directions end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/bus_time/bus_route.rb', line 6 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/bus_time/bus_route.rb', line 6 def name @name end |
#stops ⇒ Object
19 20 21 |
# File 'lib/bus_time/bus_route.rb', line 19 def stops @stops || fetch_stops end |
Instance Method Details
#display_name ⇒ Object
35 36 37 |
# File 'lib/bus_time/bus_route.rb', line 35 def display_name "#{@id} - #{@name}" end |
#fetch_directions ⇒ Object
23 24 25 |
# File 'lib/bus_time/bus_route.rb', line 23 def fetch_directions @directions = BusTime.api.fetch_directions(@id) end |
#fetch_stops ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/bus_time/bus_route.rb', line 27 def fetch_stops @directions.each do |direction| @stops = BusTime.api.fetch_stops(@id, direction) end @stops end |
#nearby_stops(_lat, _lon, _radius = DEFAULT_NEARBY_DISTANCE) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/bus_time/bus_route.rb', line 39 def nearby_stops(_lat, _lon, _radius = DEFAULT_NEARBY_DISTANCE) @stops.select do |stop| # stop.distanceFrom(lat, lon) <= radius stop end end |