class LondonTransport::Base
Constants
- API_ENDPOINT
- AVAILABLE_MODES_OF_TRANSPORT
- MODES
- STOP_TYPES
Public Class Methods
new(longitude:, latitude:, radius: 500)
click to toggle source
# File lib/london_transport/base.rb, line 7 def initialize(longitude:, latitude:, radius: 500) @longitude = longitude @latitude = latitude @radius = radius end
Public Instance Methods
stations(limit = 3)
click to toggle source
# 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(station['distance'].to_s).to_f.round(15), modes: self.class::MODES.any? ? self.class::MODES : station['modes'], lines: line.names } } end distances end
Private Instance Methods
api_endpoint()
click to toggle source
# File lib/london_transport/base.rb, line 34 def api_endpoint URI("#{API_ENDPOINT}?lat=#{@latitude}&lon=#{@longitude}&stopTypes=#{stop_types}&radius=#{@radius}&useStopPointHierarchy=True&returnLines=True&modes=#{modes}&app_id=#{LondonTransport.app_id}&app_key=#{LondonTransport.app_key}") end
modes()
click to toggle source
# File lib/london_transport/base.rb, line 42 def modes @modes ||= self.class::MODES.join(',') end
nearest()
click to toggle source
# File lib/london_transport/base.rb, line 46 def nearest Oj.load(::Net::HTTP.get(api_endpoint)) end
stop_types()
click to toggle source
# File lib/london_transport/base.rb, line 38 def stop_types @stop_types ||= self.class::STOP_TYPES.join(',') end