Sha256: 73cfbca732d7629a284deada82a278e2df6be102d91f88d82225ec71406882a5

Contents?: true

Size: 728 Bytes

Versions: 2

Compression:

Stored size: 728 Bytes

Contents

# frozen_string_literal: true

require 'japan_etc/database_provider'
require 'csv'

module JapanETC
  class Database
    CSV_HEADER = %i[
      tollbooth_id
      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.sort.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

2 entries across 2 versions & 1 rubygems

Version Path
japan_etc-0.6.0 lib/japan_etc/database.rb
japan_etc-0.5.2 lib/japan_etc/database.rb