Class: LondonTransport::Base
- Inherits:
-
Object
- Object
- LondonTransport::Base
- Defined in:
- lib/london_transport/base.rb
Constant Summary collapse
- API_ENDPOINT =
"https://api.tfl.gov.uk/StopPoint"
- STOP_TYPES =
[]
- MODES =
[]
- AVAILABLE_MODES_OF_TRANSPORT =
['bus', 'train', 'tube']
Instance Method Summary collapse
-
#initialize(longitude:, latitude:, radius: 500) ⇒ Base
constructor
A new instance of Base.
- #stations(limit = 3) ⇒ Object
Constructor Details
#initialize(longitude:, latitude:, radius: 500) ⇒ Base
Returns a new instance of Base.
7 8 9 10 11 |
# File 'lib/london_transport/base.rb', line 7 def initialize(longitude:, latitude:, radius: 500) @longitude = longitude @latitude = latitude @radius = radius end |
Instance Method Details
#stations(limit = 3) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/london_transport/base.rb', line 13 def stations(limit = 3) distances = [] return distances unless nearest nearest['stopPoints'][0..limit - 1].each do |station| line = LondonTransport::Line.new(station['lineModeGroups']) distances << { station['commonName'] => { distance: BigDecimal.new(station['distance'].to_s).to_f.round(15), modes: self.class::MODES.any? ? self.class::MODES : station['modes'], lines: line.names } } end distances end |