jp-postal-lookup-search 1.0.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: de4759f498649fc7d378a2df30f801ad06c3a053ae1f34b8a63ef4ab1e690cb5
4
+ data.tar.gz: 8ef5bfc20e89c590f0b77d5875616e79cdb545b3aa35b6214be5532676961da9
5
+ SHA512:
6
+ metadata.gz: 7f2523992d7b7e1f0288966b99c0d2bb6d9fa4ed807e46c3b92e3db4d5f530eb2330a4dc77389273b6febdff069feabdc5a5cbbd87c228d523d455da75c3d603
7
+ data.tar.gz: 14e3c097e839910d5bfabf1aaf356efd70d3085a80dba163085529685541e115b40023ecc9c4d10c73666384971d7cb11f6d71dad7cc22bb5f287cc5d6c403f2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Justin Ang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,179 @@
1
+ # JP Postal Lookup Search
2
+
3
+ ※日本語版が続きます
4
+
5
+ A project that allows lookups/searches based on japanese addresses and postal codes.
6
+ Functionality and dataset is built around the official Japan Post ken_all dataset.
7
+
8
+ Supports partial/incomplete matching, local overrides (see usage).
9
+
10
+ Example:
11
+ ```rb
12
+ require "jp_postal_lookup_search"
13
+
14
+ ...
15
+
16
+ JpPostalLookupSearch.lookup_address_by_postal_code("6500021")
17
+ # "兵庫県神戸市中央区三宮町"
18
+ JpPostalLookupSearch.search_postal_code_by_address("兵庫県神戸市中央区三宮町")
19
+ # "6500021"
20
+
21
+ JpPostalLookupSearch.lookup_address_by_postal_code("0600001")
22
+ # "北海道札幌市中央区北一条西(1~19丁目)"
23
+ JpPostalLookupSearch.search_postal_code_by_address("北海道札幌市中央区北一条西9丁目")
24
+ # "0600001"
25
+ ```
26
+
27
+ ---
28
+
29
+ このプロジェクトでは、郵便番号から住所を検索したり、住所から郵便番号を検索したりできます。
30
+ 日本郵便の公式サイトで公開されている郵便番号データ(KEN_ALL)を使用しています。
31
+
32
+ 部分一致・不完全な住所での検索や、ローカルでの上書き設定にも対応しています(Usageを参照)。
33
+
34
+ 例:
35
+ ```rb
36
+ ```
37
+
38
+ ## Methods
39
+
40
+ | Method / 関数 | Description / 説明 | Example / 例 | Speed / 速度 |
41
+ |---|---|---|---|
42
+ | `lookup_address_by_postal_code(postal_code)` | Looks up address associated with postal code / 郵便番号から住所を検索します。 | `JpPostalLookupSearch.lookup_address_by_postal_code("6500021")` | ~8.993 µs / call |
43
+ | `lookup_address_parts_by_postal_code(postal_code)` | Looks up address associated with postal code and returns object with properties / 郵便番号から住所を検索します。 | `JpPostalLookupSearch.lookup_address_parts_by_postal_code("6500021")` | ~5.062 µs / call |
44
+ | `lookup_address_kana_by_postal_code(postal_code)` | Looks up address (in kana) associated with postal code / 郵便番号から住所のカナ表記を検索します。 | `JpPostalLookupSearch.lookup_address_kana_by_postal_code("6500021")` | ~4.142 µs / call |
45
+ | `search_postal_code_by_address(address)` | Matches address to a postal code / 住所から郵便番号を検索します。 | `JpPostalLookupSearch.search_postal_code_by_address("兵庫県神戸市中央区三宮町")` | ~644.589 µs / call |
46
+
47
+ ## Usage
48
+
49
+ Installation
50
+ ```
51
+ gem install jp_postal_lookup_search
52
+ ```
53
+ Importing methods & PostalAddress class
54
+ ```rb
55
+ require "jp_postal_lookup_search"
56
+ ```
57
+
58
+ In addition to the packaged methods, this package also exposes a PostalAddress class
59
+ that can be used to manage prefecture/city/town information.
60
+
61
+ ```rb
62
+ sample_location = JpPostalLookupSearch::PostalAddress.new("6008001")
63
+ # 京都府京都市下京区真町
64
+ sample_location.update_custom(
65
+ {
66
+ pref: "東京都",
67
+ pref_kana: "トウキョウト",
68
+ }
69
+ )
70
+ sample_location.address
71
+ # 東京都京都市下京区真町
72
+ ```
73
+
74
+ Initialization takes in both postal code and address, and you can pass custom attributes directly during initialization.
75
+
76
+ ```rb
77
+ sample_location = JpPostalLookupSearch::PostalAddress.new("6008001")
78
+ sample_location = JpPostalLookupSearch::PostalAddress.new("埼玉県さいたま市大宮区宮町")
79
+ # custom
80
+ sample_location = JpPostalLookupSearch::PostalAddress.new("1020075",
81
+ {
82
+ street: "6-16",
83
+ building: "二松学舎大学 九段1・2号館",
84
+ street_kana: "6-16ニショウガクシャダイガク",
85
+ building_kana: "クダン1・2ゴウカン"
86
+ }
87
+ )
88
+ ```
89
+
90
+ You could even overwrite the kana fields with english:
91
+
92
+ ```rb
93
+ location_en_kana = JpPostalLookupSearch::PostalAddress.new("1110032",
94
+ {
95
+ pref_kana: "Tokyo-To ",
96
+ city_kana: "Taito-Ku ",
97
+ town_kana: "Asakusa ",
98
+ street_kana: "2 Chome-3-1"
99
+ }
100
+ )
101
+ location_en_kana.kana
102
+ # Tokyo-To Taito-Ku Asakusa 2 Chome-3-1
103
+ ```
104
+
105
+ ---
106
+
107
+ インストール
108
+ ```
109
+ gem install jp_postal_lookup_search
110
+ ```
111
+ 関数および PostalAddress クラスのインポート
112
+ ```rb
113
+ require "jp_postal_lookup_search"
114
+ ```
115
+
116
+ メソッドに加えて、PostalAddressで都道府県・市区町村・町域など情報を取得・調整できます。
117
+
118
+ ```rb
119
+ sample_location = JpPostalLookupSearch::PostalAddress.new("6008001")
120
+ # 京都府京都市下京区真町
121
+ sample_location.update_custom(
122
+ {
123
+ pref: "東京都",
124
+ pref_kana: "トウキョウト",
125
+ }
126
+ )
127
+ sample_location.address
128
+ ```
129
+
130
+ 郵便番号および住所から初期化できます。また、カスタム項目(都道府県・市区町村・町域など)を指定して初期化することも可能です。
131
+
132
+ ```rb
133
+ sample_location = JpPostalLookupSearch::PostalAddress.new("6008001")
134
+ sample_location = JpPostalLookupSearch::PostalAddress.new("埼玉県さいたま市大宮区宮町")
135
+ # custom
136
+ sample_location = JpPostalLookupSearch::PostalAddress.new("1020075",
137
+ {
138
+ street: "6-16",
139
+ building: "二松学舎大学 九段1・2号館",
140
+ street_kana: "6-16ニショウガクシャダイガク",
141
+ building_kana: "クダン1・2ゴウカン"
142
+ }
143
+ )
144
+ ```
145
+
146
+ カナのプロパティを英語で上書きしてしまってもいいですよ。
147
+
148
+ ```rb
149
+ location_en_kana = JpPostalLookupSearch::PostalAddress.new("1110032",
150
+ {
151
+ pref_kana: "Tokyo-To ",
152
+ city_kana: "Taito-Ku ",
153
+ town_kana: "Asakusa ",
154
+ street_kana: "2 Chome-3-1"
155
+ }
156
+ )
157
+ location_en_kana.kana
158
+ # Tokyo-To Taito-Ku Asakusa 2 Chome-3-1
159
+ ```
160
+
161
+ ## Development
162
+
163
+ The development of this project is guided by 4 principles:
164
+ 1. No callbacks. Everything should be synchronous
165
+ 2. Reduce/Eliminate external dependencies
166
+ 3. Emphasize usability, performance, extensibility
167
+ 4. Keep static files small in size
168
+
169
+ ---
170
+
171
+ このプロジェクトの実装中心点は以下になります:
172
+ 1. コールバック関数厳禁
173
+ 2. 依存パッケージなし
174
+ 3. 使いやすさ・拡張性・処理速度を重視
175
+ 4. 必要ファイル量減少
176
+
177
+ ## Future Goals
178
+
179
+ EN Translations, Github Actions Automatic Update/Build
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This module defines project-level constants.
4
+ module JpPostalLookupSearch
5
+ module Constants
6
+ EXCLUSION_TEXT = "を除く"
7
+ NOT_LISTED_BELOW_TEXT = "以下に掲載がない場合"
8
+ BUILDINGS_AFTER_EXCLUDED = "(次のビルを除く)"
9
+ OTHER = "(その他)"
10
+ ICHIEN = "一円"
11
+ SUFFIX_OPTIONS = %w[丁目 番地 番 号"].freeze
12
+ PREFECTURE_DIGITS = 3
13
+ SPECIAL_NOTES = {
14
+ BUILDINGS_AFTER_EXCLUDED => [],
15
+ OTHER => [],
16
+ ICHIEN => []
17
+ }.freeze
18
+
19
+ # REGEX Constants
20
+
21
+ HAS_PAREN_WITH_VALUES_COMMA = /(?=.*、)[((](.*?)[))]/
22
+ NUMBER_RANGE_REGEX = /(\d+)\D*[~~〜]\D*(\d+)/
23
+ STRIP_PAREN_REGEX = /[()()]/
24
+ MATCH_COMMA_REGEX = /[,,、﹑]/
25
+ MATCH_DASH_REGEX = /[-‐‑‒–—―ー-]/
26
+ MATCH_POSTAL_SYMBOL_REGEX = /〒/
27
+ MATCH_7_DIGITS = /^\d{7}$/
28
+ MATCH_ICHI_EN = /.+[市区町村]一円$/
29
+
30
+ # Errors
31
+
32
+ PREFECTURE_NOT_FOUND = "都道府県情報を検索できません。"
33
+ CITY_TOWN_NOT_FOUND = "住所情報を検索できません。"
34
+ SEARCH_FAILED_PREFECTURE = "郵便番号を検索できません。検索ステージ:都道府県"
35
+ SEARCH_FAILED_CITY = "郵便番号を検索できません。検索ステージ:市区町村"
36
+ SEARCH_FAILED_TOWN = "郵便番号を検索できません。検索ステージ:町域"
37
+ end
38
+
39
+ include Constants
40
+ end