Sha256: 604c654958b7382979b56dda03893533f9dbcfc259a27878094e0e8df8df1a88

Contents?: true

Size: 1.01 KB

Versions: 8

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

require 'japan_etc/database_provider/base'
require 'japan_etc/tollbooth'
require 'faraday'
require 'nokogiri'

module JapanETC
  module DatabaseProvider
    # http://www.nagoya-expressway.or.jp/etc/etc-lane.html
    class PastDatabase < Base
      def source_id
        'PastDatabase'
      end

      def fetch_tollbooths
        rows.map do |row|
          create_tollbooth_from_row(row)
        end
      end

      def create_tollbooth_from_row(row)
        identifier = Tollbooth::Identifier.from(row[0])

        road = Road.new(row[1], row[2])

        Tollbooth.new(
          identifier: identifier,
          road: road,
          name: row[3],
          direction: row[4],
          entrance_or_exit: row[5],
          note: row[6],
          source: source_id,
          priority: -1
        )
      end

      def rows
        CSV.parse(csv, headers: :first_row)
      end

      def csv
        path = File.join(__dir__, 'past_database.csv')
        File.read(path)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
japan_etc-0.14.0 lib/japan_etc/database_provider/past_database.rb
japan_etc-0.13.0 lib/japan_etc/database_provider/past_database.rb
japan_etc-0.12.0 lib/japan_etc/database_provider/past_database.rb
japan_etc-0.11.0 lib/japan_etc/database_provider/past_database.rb
japan_etc-0.10.0 lib/japan_etc/database_provider/past_database.rb
japan_etc-0.9.0 lib/japan_etc/database_provider/past_database.rb
japan_etc-0.8.0 lib/japan_etc/database_provider/past_database.rb
japan_etc-0.7.0 lib/japan_etc/database_provider/past_database.rb