Class: BusTracker::BusStop

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ BusStop

Returns a new instance of BusStop.



5
6
7
8
9
10
11
12
# File 'lib/bus_tracker/bus_stop.rb', line 5

def initialize(options = {})
  self.service_numbers = []
  self.departures      = []

  options.each_pair do |option, value|
    self.send("#{option}=", value) if self.respond_to? "#{option}="
  end
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



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

def code
  @code
end

#departuresObject

Returns the value of attribute departures.



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

def departures
  @departures
end

#latitudeObject

Returns the value of attribute latitude.



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

def latitude
  @latitude
end

#longitudeObject

Returns the value of attribute longitude.



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

def longitude
  @longitude
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#service_numbersObject

Returns the value of attribute service_numbers.



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

def service_numbers
  @service_numbers
end

Instance Method Details

#fetch_departures!Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/bus_tracker/bus_stop.rb', line 14

def fetch_departures!
  self.departures = []

  uri  = "#{BASE_URI}getBusStopDepartures.php?refreshCount=0&clientType=b&busStopCode=#{code}"
  uri += "&busStopDay=0&busStopService=0&numberOfPassage=4&busStopTime=&busStopDestination=0"
  document = Nokogiri::HTML(open(uri))
  document.xpath('//pre').each do |departure|
    self.departures << BusTracker::Departure.new(departure.content)
  end
end