# frozen_string_literal: true require "japan_municipality/version" require "csv" class JapanMunicipality attr_reader :area_code, :prefecture, :subprefecture attr_reader :subprefecture_furigana, :municipality, :municipality_furigana attr_reader :merger_dissolution_date, :has_merger_dissolution_infomation def self.all DATA[2..-1].map do |data| new(data) end end def initialize(data) @area_code = data[0] @prefecture = data[1] @subprefecture = data[2] @subprefecture_furigana = data[3] @municipality = data[4] @municipality_furigana = data[5] @merger_dissolution_date = data[6] @has_merger_dissolution_infomation = data[7] end # https://www.e-stat.go.jp/municipalities/cities/areacode CSV_PATH = File.expand_path("../../data/municipalities.csv", __FILE__) DATA = CSV.read(CSV_PATH).freeze private_constant :CSV_PATH, :DATA end