Class: Bmtc::BusStop

Inherits:
Object
  • Object
show all
Defined in:
lib/bmtc/bus_stop.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ BusStop

Returns a new instance of BusStop.



4
5
6
7
8
9
# File 'lib/bmtc/bus_stop.rb', line 4

def initialize(options = {})
  @id = options['StopId']
  @name = options['StopName']
  @latitude = options['StopLat']
  @longitude = options['StopLong']
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/bmtc/bus_stop.rb', line 3

def id
  @id
end

#latitudeObject (readonly)

Returns the value of attribute latitude.



3
4
5
# File 'lib/bmtc/bus_stop.rb', line 3

def latitude
  @latitude
end

#longitudeObject (readonly)

Returns the value of attribute longitude.



3
4
5
# File 'lib/bmtc/bus_stop.rb', line 3

def longitude
  @longitude
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/bmtc/bus_stop.rb', line 3

def name
  @name
end

Class Method Details

.buses_in_stop(id) ⇒ Object



16
17
18
19
20
21
# File 'lib/bmtc/bus_stop.rb', line 16

def self.buses_in_stop(id)
  options = {
    'stopID' => id
  }
  JSON.parse(Bmtc.post_request('/itsstopwise/details', options))
end

.nearest_stop(latitude, longitude, radius = 2) ⇒ Object



23
24
25
# File 'lib/bmtc/bus_stop.rb', line 23

def self.nearest_stop(latitude, longitude, radius = 2)
  Bmtc.get("/busstops/stopnearby/lat/#{latitude}/lon/#{longitude}/rad/#{radius}")
end

.search(query) ⇒ Object



11
12
13
14
# File 'lib/bmtc/bus_stop.rb', line 11

def self.search(query)
  list = JSON.parse Bmtc.get("/busstops/stopsearch/name/#{query}").body
  list.map { |stop| BMTC::BusStop.new(stop) }
end