Class: JapanETC::DatabaseProvider::HanshinExpressway

Inherits:
Base
  • Object
show all
Defined in:
lib/japan_etc/database_provider/hanshin_expressway.rb

Overview

Instance Method Summary collapse

Methods inherited from Base

#source_id

Instance Method Details

#fetch_tollboothsObject



16
17
18
19
20
# File 'lib/japan_etc/database_provider/hanshin_expressway.rb', line 16

def fetch_tollbooths
  rows.flat_map do |row|
    process_row(row)
  end.compact
end

#process_row(row) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/japan_etc/database_provider/hanshin_expressway.rb', line 22

def process_row(row)
  route_name, road_number, tollbooth_number, tollbooth_name, _, note = row

  return nil if !road_number.is_a?(Numeric) || !tollbooth_number.is_a?(Numeric)

  tollbooth = Tollbooth.create(
    road_number: road_number,
    tollbooth_number: tollbooth_number,
    road_name: '阪神高速道路',
    route_name: route_name,
    name: tollbooth_name,
    note: note,
    source: source_id
  )

  remove_redundant_name_suffix!(tollbooth)

  tollbooth
end

#remove_redundant_name_suffix!(tollbooth) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/japan_etc/database_provider/hanshin_expressway.rb', line 42

def remove_redundant_name_suffix!(tollbooth)
  return unless tollbooth.entrance_or_exit

  tollbooth.name.sub!(/[入出]\z/) do |match|
    found_entrance_or_exit = EntranceOrExit.from(match)
    found_entrance_or_exit == tollbooth.entrance_or_exit ? '' : match
  end
end

#rowsObject



51
52
53
# File 'lib/japan_etc/database_provider/hanshin_expressway.rb', line 51

def rows
  workbook.worksheets.first.rows
end

#source_urlObject



12
13
14
# File 'lib/japan_etc/database_provider/hanshin_expressway.rb', line 12

def source_url
  'https://www.hanshin-exp.co.jp/drivers/ryoukin/files/code_20200329.xls'
end

#workbookObject



55
56
57
58
# File 'lib/japan_etc/database_provider/hanshin_expressway.rb', line 55

def workbook
  response = Faraday.get(source_url)
  Spreadsheet.open(StringIO.new(response.body))
end