Class: BusTracker::BusStop
- Inherits:
-
Object
- Object
- BusTracker::BusStop
- Defined in:
- lib/bus_tracker/bus_stop.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#departures ⇒ Object
Returns the value of attribute departures.
-
#latitude ⇒ Object
Returns the value of attribute latitude.
-
#longitude ⇒ Object
Returns the value of attribute longitude.
-
#name ⇒ Object
Returns the value of attribute name.
-
#service_numbers ⇒ Object
Returns the value of attribute service_numbers.
Instance Method Summary collapse
- #fetch_departures! ⇒ Object
-
#initialize(options = {}) ⇒ BusStop
constructor
A new instance of BusStop.
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( = {}) self.service_numbers = [] self.departures = [] .each_pair do |option, value| self.send("#{option}=", value) if self.respond_to? "#{option}=" end end |
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
3 4 5 |
# File 'lib/bus_tracker/bus_stop.rb', line 3 def code @code end |
#departures ⇒ Object
Returns the value of attribute departures.
3 4 5 |
# File 'lib/bus_tracker/bus_stop.rb', line 3 def departures @departures end |
#latitude ⇒ Object
Returns the value of attribute latitude.
3 4 5 |
# File 'lib/bus_tracker/bus_stop.rb', line 3 def latitude @latitude end |
#longitude ⇒ Object
Returns the value of attribute longitude.
3 4 5 |
# File 'lib/bus_tracker/bus_stop.rb', line 3 def longitude @longitude end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/bus_tracker/bus_stop.rb', line 3 def name @name end |
#service_numbers ⇒ Object
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 |