Class: KanazawaLoopBus::BusLocationService

Inherits:
Object
  • Object
show all
Defined in:
lib/kanazawa_loop_bus/bus_location_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBusLocationService

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_timeObject (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

#busesObject



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

#fetchObject 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