japanese_address_parser 4.0.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +67 -6
  3. data/CHANGELOG.md +17 -0
  4. data/Gemfile.lock +104 -58
  5. data/Steepfile +1 -7
  6. data/japanese_address_parser.gemspec +2 -0
  7. data/lib/japanese_address_parser/address.rb +35 -34
  8. data/lib/japanese_address_parser/cache_regexes.rb +22 -14
  9. data/lib/japanese_address_parser/city.rb +14 -13
  10. data/lib/japanese_address_parser/data/api_meta.rb +8 -7
  11. data/lib/japanese_address_parser/data/machi_aza_api.rb +8 -7
  12. data/lib/japanese_address_parser/data/prefecture_api.rb +8 -7
  13. data/lib/japanese_address_parser/data/single_chiban.rb +17 -16
  14. data/lib/japanese_address_parser/data/single_city.rb +25 -24
  15. data/lib/japanese_address_parser/data/single_machi_aza.rb +28 -27
  16. data/lib/japanese_address_parser/data/single_prefecture.rb +13 -12
  17. data/lib/japanese_address_parser/data/single_rsdt.rb +17 -16
  18. data/lib/japanese_address_parser/dictionaries/convert.rb +1 -0
  19. data/lib/japanese_address_parser/fetcher.rb +13 -12
  20. data/lib/japanese_address_parser/japanese_numeral.rb +2 -0
  21. data/lib/japanese_address_parser/normalize_result_point.rb +21 -21
  22. data/lib/japanese_address_parser/prefecture.rb +15 -14
  23. data/lib/japanese_address_parser/town.rb +23 -22
  24. data/lib/japanese_address_parser/version.rb +1 -1
  25. data/sig/address.rbs +2 -5
  26. data/sig/cache_regexes.rbs +22 -25
  27. data/sig/config.rbs +0 -2
  28. data/sig/data.rbs +2 -5
  29. data/sig/dict.rbs +1 -3
  30. data/sig/dictionaries.rbs +1 -3
  31. data/sig/fetcher.rbs +5 -6
  32. data/sig/japanese_address_parser.rbs +6 -3
  33. data/sig/japanese_numeral.rbs +12 -15
  34. data/sig/kan2num.rbs +1 -3
  35. data/sig/lru_redux.rbs +9 -0
  36. data/sig/normalize.rbs +4 -7
  37. data/sig/normalize_helpers.rbs +1 -3
  38. data/sig/normalize_result.rbs +0 -2
  39. data/sig/normalize_result_point.rbs +8 -8
  40. data/sig/patch_addr.rbs +1 -3
  41. data/sig/utils.rbs +2 -4
  42. data/sig/zen2han.rbs +1 -3
  43. metadata +30 -1
@@ -9,13 +9,14 @@ require 'japanese_address_parser/data/single_prefecture'
9
9
  module JapaneseAddressParser
10
10
  module Data
11
11
  # api/ja.json のレスポンス全体(全都道府県+配下市区町村)。JS の PrefectureApi。
12
- PrefectureApi =
13
- ::Data.define(:meta, :data) do
14
- # JSON(パース済み Hash・文字列キー)から VO を生成する Ruby 独自ヘルパ。
15
- def self.from_json(hash)
16
- new(meta: ApiMeta.from_json(hash['meta']), data: (hash['data'] || []).map { |pref| SinglePrefecture.from_json(pref) })
17
- end
18
- end
12
+ PrefectureApi = ::Data.define(:meta, :data)
19
13
  public_constant :PrefectureApi
14
+
15
+ class PrefectureApi
16
+ # JSON(パース済み Hash・文字列キー)から VO を生成する Ruby 独自ヘルパ。
17
+ def self.from_json(hash)
18
+ new(meta: ApiMeta.from_json(hash['meta']), data: (hash['data'] || []).map { |pref| SinglePrefecture.from_json(pref) })
19
+ end
20
+ end
20
21
  end
21
22
  end
@@ -5,23 +5,24 @@
5
5
 
6
6
  module JapaneseAddressParser
7
7
  module Data
8
- # SingleChiban — 地番(地番1・地番2・地番3)。M8 で CSV 行から生成する。
9
- SingleChiban =
10
- ::Data.define(:prc_num1, :prc_num2, :prc_num3, :point) do
11
- # JS: chibanToString(chiban) => [prc_num1, prc_num2, prc_num3].filter(Boolean).join('-')
12
- # JS の filter(Boolean) は falsy(nil・空文字)を除外する。Ruby では空文字は truthy なので
13
- # compact だけでは不十分。nil と空文字の両方を除外して忠実に再現する。
14
- def chiban_to_string
15
- [prc_num1, prc_num2, prc_num3]
16
- .reject { |value| value.nil? || value == '' }
17
- .join('-')
18
- end
8
+ # SingleChiban — 地番(地番1・地番2・地番3)。CSV 行から生成する。
9
+ SingleChiban = ::Data.define(:prc_num1, :prc_num2, :prc_num3, :point)
10
+ public_constant :SingleChiban
19
11
 
20
- # JSON(パース済み Hash・文字列キー)から VO を生成する Ruby 独自ヘルパ。
21
- def self.from_json(hash)
22
- new(prc_num1: hash['prc_num1'], prc_num2: hash['prc_num2'], prc_num3: hash['prc_num3'], point: hash['point'])
23
- end
12
+ class SingleChiban
13
+ # JSON(パース済み Hash・文字列キー)から VO を生成する Ruby 独自ヘルパ。
14
+ def self.from_json(hash)
15
+ new(prc_num1: hash['prc_num1'], prc_num2: hash['prc_num2'], prc_num3: hash['prc_num3'], point: hash['point'])
24
16
  end
25
- public_constant :SingleChiban
17
+
18
+ # JS: chibanToString(chiban) => [prc_num1, prc_num2, prc_num3].filter(Boolean).join('-')
19
+ # JS の filter(Boolean) は falsy(nil・空文字)を除外する。Ruby では空文字は truthy なので
20
+ # compact だけでは不十分。nil と空文字の両方を除外して忠実に再現する。
21
+ def chiban_to_string
22
+ [prc_num1, prc_num2, prc_num3]
23
+ .reject { |value| value.nil? || value == '' }
24
+ .join('-')
25
+ end
26
+ end
26
27
  end
27
28
  end
@@ -8,31 +8,32 @@ module JapaneseAddressParser
8
8
  # SingleCity — api/ja.json の cities 要素(政令市の場合は区で区切られる)。
9
9
  # `::Data.define`(先頭 `::` は名前空間 JapaneseAddressParser::Data 内で
10
10
  # トップレベル定数 ::Data を指すために必須)。
11
- SingleCity =
12
- ::Data.define(:code, :county, :county_k, :county_r, :city, :city_k, :city_r, :ward, :ward_k, :ward_r, :point) do
13
- # JS: cityName(city) => `${city.county || ''}${city.city}${city.ward || ''}`
14
- # nil の補間は Ruby では空文字になるため `|| ''` 相当。
15
- def city_name
16
- "#{county}#{city}#{ward}"
17
- end
11
+ SingleCity = ::Data.define(:code, :county, :county_k, :county_r, :city, :city_k, :city_r, :ward, :ward_k, :ward_r, :point)
12
+ public_constant :SingleCity
18
13
 
19
- # JSON(パース済み Hash・文字列キー)から VO を生成する Ruby 独自ヘルパ。
20
- def self.from_json(hash)
21
- new(
22
- code: hash['code'],
23
- county: hash['county'],
24
- county_k: hash['county_k'],
25
- county_r: hash['county_r'],
26
- city: hash['city'],
27
- city_k: hash['city_k'],
28
- city_r: hash['city_r'],
29
- ward: hash['ward'],
30
- ward_k: hash['ward_k'],
31
- ward_r: hash['ward_r'],
32
- point: hash['point']
33
- )
34
- end
14
+ class SingleCity
15
+ # JSON(パース済み Hash・文字列キー)から VO を生成する Ruby 独自ヘルパ。
16
+ def self.from_json(hash)
17
+ new(
18
+ code: hash['code'],
19
+ county: hash['county'],
20
+ county_k: hash['county_k'],
21
+ county_r: hash['county_r'],
22
+ city: hash['city'],
23
+ city_k: hash['city_k'],
24
+ city_r: hash['city_r'],
25
+ ward: hash['ward'],
26
+ ward_k: hash['ward_k'],
27
+ ward_r: hash['ward_r'],
28
+ point: hash['point']
29
+ )
35
30
  end
36
- public_constant :SingleCity
31
+
32
+ # JS: cityName(city) => `${city.county || ''}${city.city}${city.ward || ''}`
33
+ # nil の補間は Ruby では空文字になるため `|| ''` 相当。
34
+ def city_name
35
+ "#{county}#{city}#{ward}"
36
+ end
37
+ end
37
38
  end
38
39
  end
@@ -8,34 +8,35 @@ module JapaneseAddressParser
8
8
  # SingleMachiAza — api/ja/{都道府県名}/{市区町村名}.json の data 要素(町字)。
9
9
  # `rsdt` は値が存在するとき必ず `true`(住居表示住所データの存在フラグ)。
10
10
  # `csv_ranges` は level 8 で住居表示/地番 CSV の該当バイト範囲を引くために保持する。
11
- SingleMachiAza =
12
- ::Data.define(:machiaza_id, :oaza_cho, :oaza_cho_k, :oaza_cho_r, :chome, :chome_n, :koaza, :koaza_k, :koaza_r, :rsdt, :point, :csv_ranges) do
13
- # JS: machiAzaName(machiAza) => `${oaza_cho || ''}${chome || ''}${koaza || ''}`
14
- # nil の補間は Ruby では空文字になるため `|| ''` 相当。
15
- def machi_aza_name
16
- "#{oaza_cho}#{chome}#{koaza}"
17
- end
11
+ SingleMachiAza = ::Data.define(:machiaza_id, :oaza_cho, :oaza_cho_k, :oaza_cho_r, :chome, :chome_n, :koaza, :koaza_k, :koaza_r, :rsdt, :point, :csv_ranges)
12
+ public_constant :SingleMachiAza
18
13
 
19
- # JSON(パース済み Hash・文字列キー)から VO を生成する Ruby 独自ヘルパ。
20
- # csv_ranges は `{ "住居表示" => { "start" => Integer, "length" => Integer }, "地番" => {...} }`
21
- # の構造をそのまま保持する(M8 で消費する)。
22
- def self.from_json(hash)
23
- new(
24
- machiaza_id: hash['machiaza_id'],
25
- oaza_cho: hash['oaza_cho'],
26
- oaza_cho_k: hash['oaza_cho_k'],
27
- oaza_cho_r: hash['oaza_cho_r'],
28
- chome: hash['chome'],
29
- chome_n: hash['chome_n'],
30
- koaza: hash['koaza'],
31
- koaza_k: hash['koaza_k'],
32
- koaza_r: hash['koaza_r'],
33
- rsdt: hash['rsdt'],
34
- point: hash['point'],
35
- csv_ranges: hash['csv_ranges']
36
- )
37
- end
14
+ class SingleMachiAza
15
+ # JSON(パース済み Hash・文字列キー)から VO を生成する Ruby 独自ヘルパ。
16
+ # csv_ranges は `{ "住居表示" => { "start" => Integer, "length" => Integer }, "地番" => {...} }`
17
+ # の構造をそのまま保持する(level 8 のデータアクセスで消費する)。
18
+ def self.from_json(hash)
19
+ new(
20
+ machiaza_id: hash['machiaza_id'],
21
+ oaza_cho: hash['oaza_cho'],
22
+ oaza_cho_k: hash['oaza_cho_k'],
23
+ oaza_cho_r: hash['oaza_cho_r'],
24
+ chome: hash['chome'],
25
+ chome_n: hash['chome_n'],
26
+ koaza: hash['koaza'],
27
+ koaza_k: hash['koaza_k'],
28
+ koaza_r: hash['koaza_r'],
29
+ rsdt: hash['rsdt'],
30
+ point: hash['point'],
31
+ csv_ranges: hash['csv_ranges']
32
+ )
38
33
  end
39
- public_constant :SingleMachiAza
34
+
35
+ # JS: machiAzaName(machiAza) => `${oaza_cho || ''}${chome || ''}${koaza || ''}`
36
+ # nil の補間は Ruby では空文字になるため `|| ''` 相当。
37
+ def machi_aza_name
38
+ "#{oaza_cho}#{chome}#{koaza}"
39
+ end
40
+ end
40
41
  end
41
42
  end
@@ -8,19 +8,20 @@ require_relative 'single_city'
8
8
  module JapaneseAddressParser
9
9
  module Data
10
10
  # SinglePrefecture — api/ja.json の data 要素(都道府県+配下の市区町村一覧)。
11
- SinglePrefecture =
12
- ::Data.define(:code, :pref, :pref_k, :pref_r, :point, :cities) do
13
- # JS: prefectureName(pref) => pref.pref
14
- def prefecture_name
15
- pref
16
- end
11
+ SinglePrefecture = ::Data.define(:code, :pref, :pref_k, :pref_r, :point, :cities)
12
+ public_constant :SinglePrefecture
17
13
 
18
- # JSON(パース済み Hash・文字列キー)から VO を生成する Ruby 独自ヘルパ。
19
- def self.from_json(hash)
20
- cities = (hash['cities'] || []).map { |city| ::JapaneseAddressParser::Data::SingleCity.from_json(city) }
21
- new(code: hash['code'], pref: hash['pref'], pref_k: hash['pref_k'], pref_r: hash['pref_r'], point: hash['point'], cities:)
22
- end
14
+ class SinglePrefecture
15
+ # JSON(パース済み Hash・文字列キー)から VO を生成する Ruby 独自ヘルパ。
16
+ def self.from_json(hash)
17
+ cities = (hash['cities'] || []).map { |city| ::JapaneseAddressParser::Data::SingleCity.from_json(city) }
18
+ new(code: hash['code'], pref: hash['pref'], pref_k: hash['pref_k'], pref_r: hash['pref_r'], point: hash['point'], cities:)
23
19
  end
24
- public_constant :SinglePrefecture
20
+
21
+ # JS: prefectureName(pref) => pref.pref
22
+ def prefecture_name
23
+ pref
24
+ end
25
+ end
25
26
  end
26
27
  end
@@ -5,23 +5,24 @@
5
5
 
6
6
  module JapaneseAddressParser
7
7
  module Data
8
- # SingleRsdt — 住居表示住所(街区符号・住居番号・住居番号2)。M8 で CSV 行から生成する。
9
- SingleRsdt =
10
- ::Data.define(:blk_num, :rsdt_num, :rsdt_num2, :point) do
11
- # JS: rsdtToString(rsdt) => [blk_num, rsdt_num, rsdt_num2].filter(Boolean).join('-')
12
- # JS の filter(Boolean) は falsy(nil・空文字)を除外する。Ruby では空文字は truthy なので
13
- # compact だけでは不十分。nil と空文字の両方を除外して忠実に再現する。
14
- def rsdt_to_string
15
- [blk_num, rsdt_num, rsdt_num2]
16
- .reject { |value| value.nil? || value == '' }
17
- .join('-')
18
- end
8
+ # SingleRsdt — 住居表示住所(街区符号・住居番号・住居番号2)。CSV 行から生成する。
9
+ SingleRsdt = ::Data.define(:blk_num, :rsdt_num, :rsdt_num2, :point)
10
+ public_constant :SingleRsdt
19
11
 
20
- # JSON(パース済み Hash・文字列キー)から VO を生成する Ruby 独自ヘルパ。
21
- def self.from_json(hash)
22
- new(blk_num: hash['blk_num'], rsdt_num: hash['rsdt_num'], rsdt_num2: hash['rsdt_num2'], point: hash['point'])
23
- end
12
+ class SingleRsdt
13
+ # JSON(パース済み Hash・文字列キー)から VO を生成する Ruby 独自ヘルパ。
14
+ def self.from_json(hash)
15
+ new(blk_num: hash['blk_num'], rsdt_num: hash['rsdt_num'], rsdt_num2: hash['rsdt_num2'], point: hash['point'])
24
16
  end
25
- public_constant :SingleRsdt
17
+
18
+ # JS: rsdtToString(rsdt) => [blk_num, rsdt_num, rsdt_num2].filter(Boolean).join('-')
19
+ # JS の filter(Boolean) は falsy(nil・空文字)を除外する。Ruby では空文字は truthy なので
20
+ # compact だけでは不十分。nil と空文字の両方を除外して忠実に再現する。
21
+ def rsdt_to_string
22
+ [blk_num, rsdt_num, rsdt_num2]
23
+ .reject { |value| value.nil? || value == '' }
24
+ .join('-')
25
+ end
26
+ end
26
27
  end
27
28
  end
@@ -16,6 +16,7 @@ module JapaneseAddressParser
16
16
  # return { ...acc, [d.src]: pattern, [d.dst]: pattern }
17
17
  # }, {})
18
18
  # 既存キーへの再代入は位置を保って値を更新する(JS object と Ruby Hash で同挙動)。
19
+ # @type var pattern_map: ::Hash[::String, ::String]
19
20
  pattern_map = {}
20
21
  Dictionary::DICTIONARY.each do |entry|
21
22
  pattern = "(#{entry[:src]}|#{entry[:dst]})"
@@ -16,19 +16,20 @@ module JapaneseAddressParser
16
16
  module Fetcher
17
17
  # 取得結果。JS の FetchResponseLike `{ json(), text(), ok }` に対応する。
18
18
  # body は UTF-8 の生文字列、ok は取得成功フラグ。
19
- Response =
20
- ::Data.define(:body, :ok) do
21
- # JS: json: async () => JSON.parse(contents.toString('utf-8'))
22
- def json
23
- ::JSON.parse(body)
24
- end
19
+ Response = ::Data.define(:body, :ok)
20
+ public_constant :Response
25
21
 
26
- # JS: text: async () => contents.toString('utf-8')
27
- def text
28
- body
29
- end
22
+ class Response
23
+ # JS: json: async () => JSON.parse(contents.toString('utf-8'))
24
+ def json
25
+ ::JSON.parse(body)
30
26
  end
31
- public_constant :Response
27
+
28
+ # JS: text: async () => contents.toString('utf-8')
29
+ def text
30
+ body
31
+ end
32
+ end
32
33
 
33
34
  # User-Agent のコメント部で自己申告する本 gem の homepage。
34
35
  HOMEPAGE_URL = 'https://github.com/yamat47/japanese_address_parser'
@@ -84,7 +85,7 @@ module JapaneseAddressParser
84
85
  request['Range'] = "bytes=#{offset}-#{offset + length - 1}" unless offset.nil? || length.nil?
85
86
 
86
87
  response =
87
- ::Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.is_a?(::URI::HTTPS)) do |http|
88
+ ::Net::HTTP.start(uri.hostname.to_s, uri.port, use_ssl: uri.is_a?(::URI::HTTPS)) do |http|
88
89
  http.request(request)
89
90
  end
90
91
 
@@ -152,6 +152,7 @@ module JapaneseAddressParser
152
152
  # 進める(ECMAScript の lastIndex 前進と同じ)。
153
153
  def ecmascript_global_match(text, pattern)
154
154
  anchored = ::Regexp.new("\\A(?:#{pattern})\\z")
155
+ # @type var matches: ::Array[::String]
155
156
  matches = []
156
157
  position = 0
157
158
  while position <= text.length
@@ -187,6 +188,7 @@ module JapaneseAddressParser
187
188
  # JS: splitLargeNumber(japanese) — 漢数字を兆・億・万単位に分割する
188
189
  def split_large_number(japanese)
189
190
  kanji = japanese
191
+ # @type var numbers: ::Hash[::String, ::Integer]
190
192
  numbers = {}
191
193
  LARGE_NUMBERS.each_key do |key|
192
194
  match = kanji.match(::Regexp.new("(.+)#{key}"))
@@ -2,34 +2,34 @@
2
2
 
3
3
  # Port of: https://github.com/geolonia/normalize-japanese-addresses/blob/49c1ae4be9d2ba353b86eaf40fd7eb12a1269f3e/src/types.ts
4
4
  # Upstream: @geolonia/normalize-japanese-addresses v3.1.3
5
- # NormalizeResultPoint と座標変換ヘルパ(rsdtOrChibanToResultPoint は M8、
6
- # isNormalizeResultPoint は公開 API 検証とともに M6 で移植する)。
5
+ # NormalizeResultPoint と座標変換ヘルパ。
7
6
 
8
7
  module JapaneseAddressParser
9
8
  # 正規化結果の位置情報(EPSG:4326 / WGS84)。level は座標の正確さ(1:県 2:市 3:町字 8:住居表示/地番)。
10
- NormalizeResultPoint =
11
- ::Data.define(:lat, :lng, :level) do
12
- # Ruby 独自の補助コンストラクタ: [lng, lat] 配列(無ければ nil)から VO を作る。
13
- # 上流 types.ts の *ToResultPoint は VO の .point を直接受けるため逐語移植のまま残し、
14
- # metadata の Hash([lng, lat] 配列)から組み立てる M6 リッチ VO 層はこのファクトリを共有する。
15
- def self.from_lng_lat(point, level:)
16
- return if point.nil?
9
+ NormalizeResultPoint = ::Data.define(:lat, :lng, :level)
10
+ public_constant :NormalizeResultPoint
11
+
12
+ class NormalizeResultPoint
13
+ # Ruby 独自の補助コンストラクタ: [lng, lat] 配列(無ければ nil)から VO を作る。
14
+ # 上流 types.ts の *ToResultPoint は VO の .point を直接受けるため逐語移植のまま残し、
15
+ # metadata の Hash([lng, lat] 配列)から組み立てるリッチ VO 層はこのファクトリを共有する。
16
+ def self.from_lng_lat(point, level:)
17
+ return if point.nil?
17
18
 
18
- new(lat: point[1], lng: point[0], level:)
19
- end
19
+ new(lat: point[1], lng: point[0], level:)
20
+ end
20
21
 
21
- # JS: isNormalizeResultPoint(obj) — 任意の値が NormalizeResultPoint の形か検証する type guard。
22
- # JS は object のプロパティ存在+数値型を見る。Ruby では lat/lng/level に応答し、それらが
23
- # Numeric かつ level が 1/2/3/8 のいずれか、で判定する(JS↔Ruby のオブジェクトモデル差のため
24
- # Hash は対象外=working_agreement §3-4。挙動は spec に固定する)。
25
- def self.normalize_result_point?(obj)
26
- return false unless obj.respond_to?(:lat) && obj.respond_to?(:lng) && obj.respond_to?(:level)
27
- return false unless obj.lat.is_a?(::Numeric) && obj.lng.is_a?(::Numeric) && obj.level.is_a?(::Numeric)
22
+ # JS: isNormalizeResultPoint(obj) — 任意の値が NormalizeResultPoint の形か検証する type guard。
23
+ # JS は object のプロパティ存在+数値型を見る。Ruby では lat/lng/level に応答し、それらが
24
+ # Numeric かつ level が 1/2/3/8 のいずれか、で判定する(JS↔Ruby のオブジェクトモデル差のため
25
+ # Hash は対象外=working_agreement §3-4。挙動は spec に固定する)。
26
+ def self.normalize_result_point?(obj)
27
+ return false unless obj.respond_to?(:lat) && obj.respond_to?(:lng) && obj.respond_to?(:level)
28
+ return false unless obj.lat.is_a?(::Numeric) && obj.lng.is_a?(::Numeric) && obj.level.is_a?(::Numeric)
28
29
 
29
- [1, 2, 3, 8].include?(obj.level) # JS: validLevels = [1, 2, 3, 8]
30
- end
30
+ [1, 2, 3, 8].include?(obj.level) # JS: validLevels = [1, 2, 3, 8]
31
31
  end
32
- public_constant :NormalizeResultPoint
32
+ end
33
33
 
34
34
  # Single* VO(point は [lng, lat])から NormalizeResultPoint を作る変換ヘルパ群。
35
35
  module ResultPoint
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Rich value object exposed by the v4 public API (M6).
3
+ # Rich value object exposed by the v4 public API.
4
4
  # Ruby-original enrichment layer over the faithful NormalizeResult (working_agreement §1-3).
5
5
  # 供給元: NormalizeResult#metadata.prefecture(Omit<SinglePrefecture, 'cities'> 相当の Hash)。
6
6
 
@@ -8,20 +8,21 @@ require 'japanese_address_parser/normalize_result_point'
8
8
 
9
9
  module JapaneseAddressParser
10
10
  # 都道府県のリッチ VO。point は代表点(NormalizeResultPoint, level 1)。
11
- Prefecture =
12
- ::Data.define(:name, :code, :name_kana, :name_romaji, :point) do
13
- # metadata.prefecture(cities を除いた Hash・Symbol キー)から VO を作る。pref 未判別なら nil。
14
- # point(level 1 代表点)は都道府県データに必ず存在する(from_lng_lat は nil 受けも安全)。
15
- def self.from_metadata(hash)
16
- return if hash.nil?
11
+ Prefecture = ::Data.define(:name, :code, :name_kana, :name_romaji, :point)
12
+ public_constant :Prefecture
17
13
 
18
- new(name: hash[:pref], code: hash[:code], name_kana: hash[:pref_k], name_romaji: hash[:pref_r], point: NormalizeResultPoint.from_lng_lat(hash[:point], level: 1))
19
- end
14
+ class Prefecture
15
+ # metadata.prefecture(cities を除いた Hash・Symbol キー)から VO を作る。pref 未判別なら nil。
16
+ # point(level 1 代表点)は都道府県データに必ず存在する(from_lng_lat は nil 受けも安全)。
17
+ def self.from_metadata(hash)
18
+ return if hash.nil?
20
19
 
21
- # 緯度経度をネストも含めて Hash 化する Ruby 独自 API。
22
- def to_h
23
- { name:, code:, name_kana:, name_romaji:, point: point.to_h }
24
- end
20
+ new(name: hash[:pref], code: hash[:code], name_kana: hash[:pref_k], name_romaji: hash[:pref_r], point: NormalizeResultPoint.from_lng_lat(hash[:point], level: 1))
25
21
  end
26
- public_constant :Prefecture
22
+
23
+ # 緯度経度をネストも含めて Hash 化する Ruby 独自 API。
24
+ def to_h
25
+ { name:, code:, name_kana:, name_romaji:, point: point.to_h }
26
+ end
27
+ end
27
28
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Rich value object exposed by the v4 public API (M6).
3
+ # Rich value object exposed by the v4 public API.
4
4
  # Ruby-original enrichment layer over the faithful NormalizeResult (working_agreement §1-3).
5
5
  # 供給元: NormalizeResult#metadata.machi_aza(Omit<SingleMachiAza, 'csv_ranges'> 相当の Hash)。
6
6
 
@@ -9,28 +9,29 @@ require 'japanese_address_parser/normalize_result_point'
9
9
  module JapaneseAddressParser
10
10
  # 町字のリッチ VO。name は machiAzaName(大字+丁目+小字)。point は代表点(NormalizeResultPoint, level 3)。
11
11
  # chome は "一丁目" 等の文字列、chome_n は 1 等の整数(JS SingleMachiAza が両方持つため両方公開する)。
12
- Town =
13
- ::Data.define(:name, :machiaza_id, :chome, :chome_n, :koaza, :point) do
14
- # metadata.machi_aza(csv_ranges を除いた Hash・Symbol キー)から VO を作る。town 未判別なら nil。
15
- # point(level 3 代表点)は町字によっては存在しないため from_lng_lat が nil を返す。
16
- # name は Hash 入力のため SingleMachiAza#machi_aza_name を呼べない。式は同メソッド(JS: machiAzaName)と一致させる。
17
- def self.from_metadata(hash)
18
- return if hash.nil?
12
+ Town = ::Data.define(:name, :machiaza_id, :chome, :chome_n, :koaza, :point)
13
+ public_constant :Town
19
14
 
20
- new(
21
- name: "#{hash[:oaza_cho]}#{hash[:chome]}#{hash[:koaza]}",
22
- machiaza_id: hash[:machiaza_id],
23
- chome: hash[:chome],
24
- chome_n: hash[:chome_n],
25
- koaza: hash[:koaza],
26
- point: NormalizeResultPoint.from_lng_lat(hash[:point], level: 3)
27
- )
28
- end
15
+ class Town
16
+ # metadata.machi_aza(csv_ranges を除いた Hash・Symbol キー)から VO を作る。town 未判別なら nil。
17
+ # point(level 3 代表点)は町字によっては存在しないため from_lng_lat が nil を返す。
18
+ # name は Hash 入力のため SingleMachiAza#machi_aza_name を呼べない。式は同メソッド(JS: machiAzaName)と一致させる。
19
+ def self.from_metadata(hash)
20
+ return if hash.nil?
29
21
 
30
- # 緯度経度をネストも含めて Hash 化する Ruby 独自 API。
31
- def to_h
32
- { name:, machiaza_id:, chome:, chome_n:, koaza:, point: point&.to_h }
33
- end
22
+ new(
23
+ name: "#{hash[:oaza_cho]}#{hash[:chome]}#{hash[:koaza]}",
24
+ machiaza_id: hash[:machiaza_id],
25
+ chome: hash[:chome],
26
+ chome_n: hash[:chome_n],
27
+ koaza: hash[:koaza],
28
+ point: NormalizeResultPoint.from_lng_lat(hash[:point], level: 3)
29
+ )
34
30
  end
35
- public_constant :Town
31
+
32
+ # 緯度経度をネストも含めて Hash 化する Ruby 独自 API。
33
+ def to_h
34
+ { name:, machiaza_id:, chome:, chome_n:, koaza:, point: point&.to_h }
35
+ end
36
+ end
36
37
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JapaneseAddressParser
4
- VERSION = '4.0.0'
4
+ VERSION = '4.0.1'
5
5
  public_constant :VERSION
6
6
  end
data/sig/address.rbs CHANGED
@@ -1,8 +1,5 @@
1
- # Interim signature for the v4.0.0 public value objects (M6).
2
- # The full RBS overhaul happens in M9.
3
- #
4
- # These are `Data.define` value objects, but the bundled RBS (rbs 2.6.0) predates the
5
- # core `Data` class, so they are declared as plain classes exposing the interface we use.
1
+ # These are `Data.define` value objects, declared as plain classes exposing the
2
+ # interface we use (attr_reader + keyword-argument new).
6
3
 
7
4
  module JapaneseAddressParser
8
5
  class Prefecture
@@ -1,6 +1,3 @@
1
- # Interim signature for the v4.0.0 config & data-access layer (M3/M4).
2
- # The full RBS overhaul happens in M9.
3
- #
4
1
  # LruRedux には RBS が無いため、キャッシュ関連は untyped で受ける。
5
2
  # 町字パターン配列の要素は SingleMachiAza か TownAlias の混在なので untyped にしている。
6
3
 
@@ -23,28 +20,28 @@ module JapaneseAddressParser
23
20
  @cached_towns: Hash[String, Data::MachiAzaApi]?
24
21
  @cached_same_named_prefecture_city_regex_patterns: Array[[String, String]]?
25
22
 
26
- def self.cache: () -> untyped
27
- def self.fetch_from_cache: (String key) { () -> untyped } -> untyped
28
- def self.reset!: () -> nil
29
- def self.get_prefectures: () -> Data::PrefectureApi
30
- def self.cache_prefectures: (Data::PrefectureApi data) -> Data::PrefectureApi
31
- def self.get_prefecture_regex_patterns: (Data::PrefectureApi api) -> Array[[Data::SinglePrefecture, String]]
32
- def self.get_city_regex_patterns: (Data::SinglePrefecture pref) -> Array[[Data::SingleCity, String]]
33
- def self.get_towns: (Data::SinglePrefecture pref_obj, Data::SingleCity city_obj, Integer api_version) -> Data::MachiAzaApi
34
- def self.get_town_regex_patterns: (Data::SinglePrefecture pref, Data::SingleCity city, Integer api_version) -> Array[[untyped, String]]
35
- def self.get_same_named_prefecture_city_regex_patterns: (Data::PrefectureApi pref_api) -> Array[[String, String]]
36
- def self.get_rsdt: (Data::SinglePrefecture pref, Data::SingleCity city, Data::SingleMachiAza town, Integer api_version) -> Array[Data::SingleRsdt]
37
- def self.get_chiban: (Data::SinglePrefecture pref, Data::SingleCity city, Data::SingleMachiAza town, Integer api_version) -> Array[Data::SingleChiban]
38
- def self.fetch_subresource: (String kind, Data::SinglePrefecture pref, Data::SingleCity city, Hash[String, Integer] row, Integer api_version) -> String
39
- def self.parse_subresource: (String data) -> Array[untyped]
40
- def self.point_from: (untyped lng, untyped lat) -> [Float, Float]?
23
+ def self?.cache: () -> untyped
24
+ def self?.fetch_from_cache: (String key) { () -> untyped } -> untyped
25
+ def self?.reset!: () -> nil
26
+ def self?.get_prefectures: () -> Data::PrefectureApi
27
+ def self?.cache_prefectures: (Data::PrefectureApi data) -> Data::PrefectureApi
28
+ def self?.get_prefecture_regex_patterns: (Data::PrefectureApi api) -> Array[[Data::SinglePrefecture, String]]
29
+ def self?.get_city_regex_patterns: (Data::SinglePrefecture pref) -> Array[[Data::SingleCity, String]]
30
+ def self?.get_towns: (Data::SinglePrefecture pref_obj, Data::SingleCity city_obj, Integer api_version) -> Data::MachiAzaApi
31
+ def self?.get_town_regex_patterns: (Data::SinglePrefecture pref, Data::SingleCity city, Integer api_version) -> Array[[untyped, String]]
32
+ def self?.get_same_named_prefecture_city_regex_patterns: (Data::PrefectureApi pref_api) -> Array[[String, String]]
33
+ def self?.get_rsdt: (Data::SinglePrefecture pref, Data::SingleCity city, Data::SingleMachiAza town, Integer api_version) -> Array[Data::SingleRsdt]
34
+ def self?.get_chiban: (Data::SinglePrefecture pref, Data::SingleCity city, Data::SingleMachiAza town, Integer api_version) -> Array[Data::SingleChiban]
35
+ def self?.fetch_subresource: (String kind, Data::SinglePrefecture pref, Data::SingleCity city, Hash[String, Integer] row, Integer api_version) -> String
36
+ def self?.parse_subresource: (String data) -> Array[untyped]
37
+ def self?.point_from: (untyped lng, untyped lat) -> [Float, Float]?
41
38
 
42
- def self.cached_city_patterns: () -> Hash[Integer, Array[[Data::SingleCity, String]]]
43
- def self.cached_towns: () -> Hash[String, Data::MachiAzaApi]
44
- def self.stable_sort_by: (untyped list) { (untyped) -> untyped } -> untyped
45
- def self.town_sort_length: (untyped town) -> Integer
46
- def self.kanji_number_followed_by_cho?: (String target_town_name) -> bool
47
- def self.town_pattern_source: (String name) -> String
48
- def self.expand_town_number: (String match) -> String
39
+ def self?.cached_city_patterns: () -> Hash[Integer, Array[[Data::SingleCity, String]]]
40
+ def self?.cached_towns: () -> Hash[String, Data::MachiAzaApi]
41
+ def self?.stable_sort_by: (untyped list) { (untyped) -> untyped } -> untyped
42
+ def self?.town_sort_length: (untyped town) -> Integer
43
+ def self?.kanji_number_followed_by_cho?: (String target_town_name) -> bool
44
+ def self?.town_pattern_source: (String name) -> String
45
+ def self?.expand_town_number: (String match) -> String
49
46
  end
50
47
  end
data/sig/config.rbs CHANGED
@@ -1,5 +1,3 @@
1
- # Interim signature for the v4.0.0 config & data-access layer (M3).
2
- # The full RBS overhaul happens in M9.
3
1
 
4
2
  module JapaneseAddressParser
5
3
  class Config
data/sig/data.rbs CHANGED
@@ -1,8 +1,5 @@
1
- # Interim signatures for the v4.0.0 data model layer (M1).
2
- # The full RBS overhaul happens in M9; these keep `steep check` green in the meantime.
3
- #
4
- # These are `Data.define` value objects, but the bundled RBS (rbs 2.6.0) predates the
5
- # core `Data` class, so they are declared as plain classes exposing the interface we use.
1
+ # These are `Data.define` value objects, declared as plain classes exposing the
2
+ # interface we use (attr_reader + keyword-argument new).
6
3
 
7
4
  module JapaneseAddressParser
8
5
  module Data
data/sig/dict.rbs CHANGED
@@ -1,8 +1,6 @@
1
- # Interim signature for the v4.0.0 utility layer (M2).
2
- # The full RBS overhaul happens in M9.
3
1
 
4
2
  module JapaneseAddressParser
5
3
  module Dict
6
- def self.to_regex_pattern: (String string) -> String
4
+ def self?.to_regex_pattern: (String string) -> String
7
5
  end
8
6
  end
data/sig/dictionaries.rbs CHANGED
@@ -1,5 +1,3 @@
1
- # Interim signature for the v4.0.0 utility layer (M2).
2
- # The full RBS overhaul happens in M9.
3
1
 
4
2
  module JapaneseAddressParser
5
3
  module Dictionaries
@@ -15,7 +13,7 @@ module JapaneseAddressParser
15
13
  PATTERN_MAP: Hash[String, String]
16
14
  REGEXP: Regexp
17
15
 
18
- def self.call: (String regex_text) -> String
16
+ def self?.call: (String regex_text) -> String
19
17
  end
20
18
  end
21
19
  end