Sha256: 9ac4f3618b27782f2f9da48cd3e11df3197f46d125a083e890fd64a35a0d9ced

Contents?: true

Size: 745 Bytes

Versions: 1

Compression:

Stored size: 745 Bytes

Contents

# frozen_string_literal: true

require 'japan_etc/database_provider'
require 'csv'

module JapanETC
  class Database
    CSV_HEADER = %i[
      road_number
      tollbooth_number
      road_name
      route_name
      tollbooth_name
      direction
      entrance_or_exit
      notes
    ].freeze

    def roads
      tollbooths.map(&:road).uniq
    end

    def tollbooths
      @tollbooths ||= providers.map(&:fetch_tollbooths).flatten.uniq
    end

    def save_as_csv(filename: 'database/japan_etc_tollbooths.csv')
      CSV.open(filename, 'w') do |csv|
        csv << CSV_HEADER
        tollbooths.each { |tollbooth| csv << tollbooth.to_a }
      end
    end

    def providers
      DatabaseProvider::Base.all.map(&:new)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
japan_etc-0.1.0 lib/japan_etc/database.rb