Class: KanazawaLoopBus::BusLocationService
- Inherits:
-
Object
- Object
- KanazawaLoopBus::BusLocationService
- Defined in:
- lib/kanazawa_loop_bus/bus_location_service.rb
Instance Attribute Summary collapse
-
#fetch_time ⇒ Object
readonly
Returns the value of attribute fetch_time.
Instance Method Summary collapse
- #buses ⇒ Object
- #fetch ⇒ Object (also: #refetch!)
-
#initialize ⇒ BusLocationService
constructor
A new instance of BusLocationService.
Constructor Details
#initialize ⇒ BusLocationService
Returns a new instance of BusLocationService.
9 10 11 |
# File 'lib/kanazawa_loop_bus/bus_location_service.rb', line 9 def initialize fetch end |
Instance Attribute Details
#fetch_time ⇒ Object (readonly)
Returns the value of attribute fetch_time.
7 8 9 |
# File 'lib/kanazawa_loop_bus/bus_location_service.rb', line 7 def fetch_time @fetch_time end |
Instance Method Details
#buses ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/kanazawa_loop_bus/bus_location_service.rb', line 20 def buses @doc.xpath('//td/img').select { |img| /\.\.\/img\/busicon\/car_s_.\.gif/ =~ img["src"] }.map { |img| Bus.from_node(img) } end |
#fetch ⇒ Object Also known as: refetch!
13 14 15 16 17 |
# File 'lib/kanazawa_loop_bus/bus_location_service.rb', line 13 def fetch @doc = Nokogiri::HTML(fetch_html) raise "Service Finished" if service_finished? @fetch_time = Time.now end |