class JapanETC::DatabaseProvider::HanshinExpressway

www.hanshin-exp.co.jp/drivers/ryoukin/etc_ryokinsyo/

Public Instance Methods

fetch_tollbooths() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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
rows() click to toggle source
# File lib/japan_etc/database_provider/hanshin_expressway.rb, line 51
def rows
  workbook.worksheets.first.rows
end
source_url() click to toggle source
# 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
workbook() click to toggle source
# 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