Class: BusTime::BusStop
- Inherits:
-
Object
- Object
- BusTime::BusStop
- Defined in:
- lib/bus_time/bus_stop.rb
Overview
Service bus stop handling, including prediction retrieval via ‘BusTime::Api`
Instance Attribute Summary collapse
-
#direction ⇒ Object
Returns the value of attribute direction.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#lat ⇒ Object
readonly
Returns the value of attribute lat.
-
#lon ⇒ Object
readonly
Returns the value of attribute lon.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
- #predictions ⇒ Object
-
#routes ⇒ Object
Returns the value of attribute routes.
Instance Method Summary collapse
- #distance_from(lat, lon) ⇒ Object
- #fetch_predictions ⇒ Object
-
#initialize(id, name, coords:, direction:, routes: []) ⇒ BusStop
constructor
A new instance of BusStop.
- #nearby?(lat, lon, max_nearby_distance = BusTime.nearby_distance) ⇒ Boolean
Constructor Details
#initialize(id, name, coords:, direction:, routes: []) ⇒ BusStop
Returns a new instance of BusStop.
11 12 13 14 15 16 17 18 |
# File 'lib/bus_time/bus_stop.rb', line 11 def initialize(id, name, coords:, direction:, routes: []) @id = id @name = name @lat, @lon = coords @direction = direction @routes = routes end |
Instance Attribute Details
#direction ⇒ Object
Returns the value of attribute direction.
9 10 11 |
# File 'lib/bus_time/bus_stop.rb', line 9 def direction @direction end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/bus_time/bus_stop.rb', line 5 def id @id end |
#lat ⇒ Object (readonly)
Returns the value of attribute lat.
5 6 7 |
# File 'lib/bus_time/bus_stop.rb', line 5 def lat @lat end |
#lon ⇒ Object (readonly)
Returns the value of attribute lon.
5 6 7 |
# File 'lib/bus_time/bus_stop.rb', line 5 def lon @lon end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/bus_time/bus_stop.rb', line 5 def name @name end |
#predictions ⇒ Object
20 21 22 |
# File 'lib/bus_time/bus_stop.rb', line 20 def predictions @predictions || fetch_predictions end |
#routes ⇒ Object
Returns the value of attribute routes.
9 10 11 |
# File 'lib/bus_time/bus_stop.rb', line 9 def routes @routes end |
Instance Method Details
#distance_from(lat, lon) ⇒ Object
28 29 30 31 32 |
# File 'lib/bus_time/bus_stop.rb', line 28 def distance_from(lat, lon) require "geocoder" Geocoder::Calculations.distance_between([@lat, @lon], [lat, lon]) end |
#fetch_predictions ⇒ Object
24 25 26 |
# File 'lib/bus_time/bus_stop.rb', line 24 def fetch_predictions @predictions = BusTime.api.fetch_predictions(@id) end |
#nearby?(lat, lon, max_nearby_distance = BusTime.nearby_distance) ⇒ Boolean
34 35 36 |
# File 'lib/bus_time/bus_stop.rb', line 34 def nearby?(lat, lon, max_nearby_distance = BusTime.nearby_distance) distance_from(lat, lon) <= max_nearby_distance end |