Class: KanazawaLoopBus::Bus

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

Constant Summary collapse

NAMES =
[
  "鏡花号",
  "鏡花号",
  "秋声号",
  "犀星号"
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(option) ⇒ Bus

Returns a new instance of Bus.



26
27
28
29
30
# File 'lib/kanazawa_loop_bus/bus.rb', line 26

def initialize(option)
  @id = option[:id] 
  @previous_stop = BusStop.from_name(option[:previous_stop_name])
  @next_stop = BusStop.from_name(option[:next_stop_name])
end

Instance Attribute Details

#next_stopObject (readonly)

Returns the value of attribute next_stop.



5
6
7
# File 'lib/kanazawa_loop_bus/bus.rb', line 5

def next_stop
  @next_stop
end

#previous_stopObject (readonly)

Returns the value of attribute previous_stop.



5
6
7
# File 'lib/kanazawa_loop_bus/bus.rb', line 5

def previous_stop
  @previous_stop
end

Class Method Details

.from_node(node) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/kanazawa_loop_bus/bus.rb', line 15

def from_node(node)
  node = node.parent.parent
  id = /\.\.\/img\/busicon\/car_s_(\d)\.gif/.match(node["src"]).to_a[1].to_i or raise "Bus not found"
  Bus.new({
    id: id-1,
    previous_stop_name: node.previous.css('font').inner_text,
    next_stop_name: node.next.css('font').inner_text
  })
end

Instance Method Details

#nameObject



32
33
34
# File 'lib/kanazawa_loop_bus/bus.rb', line 32

def name
  NAMES[@id]
end