Class: JapanETC::DatabaseProvider::NagoyaExpressway
- Defined in:
- lib/japan_etc/database_provider/nagoya_expressway.rb
Overview
Defined Under Namespace
Classes: Row
Instance Method Summary collapse
Methods inherited from Base
Instance Method Details
#doc ⇒ Object
62 63 64 65 |
# File 'lib/japan_etc/database_provider/nagoya_expressway.rb', line 62 def doc response = Faraday.get(source_url) Nokogiri(response.body) end |
#fetch_tollbooths ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/japan_etc/database_provider/nagoya_expressway.rb', line 16 def fetch_tollbooths rows.map do |row| begin road_number = Integer(row[4]) tollbooth_number = Integer(row[5]) rescue ArgumentError, TypeError next end Tollbooth.create( road_number: road_number, tollbooth_number: tollbooth_number, road_name: '名古屋高速道路', route_name: row[0], name: row[2], source: source_id ) end.compact end |
#raw_rows ⇒ Object
58 59 60 |
# File 'lib/japan_etc/database_provider/nagoya_expressway.rb', line 58 def raw_rows doc.css('tr') end |
#rows ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/japan_etc/database_provider/nagoya_expressway.rb', line 36 def rows raw_rows.each_with_object([]).map do |tr, pending_subsequent_rows| current_row = pending_subsequent_rows.shift || Row.new tr.css('td,th').each_with_index do |td, column_index| text = td.text.tr(' ', '') current_row[column_index] = text next unless td.attr('rowspan') subsequent_row_count = Integer(td.attr('rowspan')) - 1 (0...subsequent_row_count).each do |row_index| subsequent_row = (pending_subsequent_rows[row_index] ||= Row.new) subsequent_row[column_index] = text end end current_row.to_a end end |
#source_url ⇒ Object
12 13 14 |
# File 'lib/japan_etc/database_provider/nagoya_expressway.rb', line 12 def source_url 'https://www.nagoya-expressway.or.jp/etc/etc-lane.html' end |