11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/japanese/train/access.rb', line 11
def self.route
puts "出発駅を入力してください"
start = STDIN.gets.strip
puts "終着駅を入力してください"
finish = STDIN.gets.strip
url = "http://transit.yahoo.co.jp/search/result?flatlon=&from=#{start}&tlatlon=&to=#{finish}"
url_escape = URI.escape(url)
page = Nokogiri::HTML.parse(open(url_escape).read)
3.times do |i|
route = "ルート#{i+1}"
route_box = page.css("#route0#{i+1}")
puts route
puts route_box.css('.routeSummary .time').text
puts route_box.css('.fare span').text.match(/\d+/).to_s + '円'
time = route_box.css('.routeDetail .station .time').map(&:text).map(&:strip)
station = route_box.css('.station dl dt a').map(&:text)
access = route_box.css('.access div').text.delete("[train]").strip.split
station.count.times do |i|
puts time[i] + " " + station[i]
puts access[i]
next unless access
end
end
end
|