29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/japanese_address_parser/csv_parser.rb', line 29
def call
filepath = Pathname(__FILE__).dirname.join('../../geolonia-japanese-addresses/data/latest.csv')
= proc { |h| ::JapaneseAddressParser::CsvParser::HEADER_MAP[h] }
data = ::CSV.table(filepath, header_converters: , converters: nil)
prefectures = {}
data.each do |row|
current_prefecture = _find_or_build_prefecture(prefectures.keys, row)
prefectures[current_prefecture] ||= {}
current_city = _find_or_build_city(prefectures[current_prefecture].keys, current_prefecture, row)
prefectures[current_prefecture][current_city] ||= []
stored_town = _find_town(prefectures[current_prefecture][current_city], row)
stored_town.nil? && (prefectures[current_prefecture][current_city] << _build_town(row))
end
_write_csv(prefectures)
end
|