Class: SMTUC::Stop

Inherits:
Object
  • Object
show all
Defined in:
lib/smtuc/stop.rb

Constant Summary collapse

API_URL =

This is a bit hacky because the only way to grab all stops is to do a lat/lon search and expand the range as high as it will go. In theory, this will return every stop in the system.

"#{BASE_API_URL}/Stops".freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Stop

Returns a new instance of Stop.



10
11
12
13
14
15
# File 'lib/smtuc/stop.rb', line 10

def initialize(attributes)
  @id = attributes['Code'].gsub('SMTUC_', '')
  @name = attributes['Name'].strip
  @lat = attributes['CoordX']
  @lon = attributes['CoordY']
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/smtuc/stop.rb', line 3

def id
  @id
end

#latObject

Returns the value of attribute lat.



3
4
5
# File 'lib/smtuc/stop.rb', line 3

def lat
  @lat
end

#lonObject

Returns the value of attribute lon.



3
4
5
# File 'lib/smtuc/stop.rb', line 3

def lon
  @lon
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/smtuc/stop.rb', line 3

def name
  @name
end

Class Method Details

.allObject

Returns a list of all known stops



18
19
20
21
22
# File 'lib/smtuc/stop.rb', line 18

def self.all
  response = Faraday.get(API_URL + '/GetStops?oLat=40.20343598944182&oLon=-8.417298279776674&meters=99999999999')
  lines = JSON.parse(response.body)
  lines.map { |line| new(line) }
end