addressing 0.2.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f6ea26657e38313826abc6c9dbab406b426b07ac6d03af922ab130d6b00e29f
4
- data.tar.gz: d3037ec9973ae1e7f0054eece0bd3e1a7a683eda4f2c4b1ad04294b3112684c6
3
+ metadata.gz: 659b1dd0f7f34037b67ac6695c23de7900feb573c65c24d45d0e485569151c41
4
+ data.tar.gz: 457905c5e2e0fa9671d0bf0e4b5b5b6ad27c73d651536f79d5667b1fcbdd8866
5
5
  SHA512:
6
- metadata.gz: 6db0b294a6ee4fb0cbb787a86e0fe506c539ea5a94ae7cb170373524540dd44a2139c90d0b6951d34728b42b19a84e3eed60bb7d50e8685ce4b65f9c21bbabb6
7
- data.tar.gz: d6a857986eff573f2e136ccd1a07eb8b0da618ce00cb78af44590708a7dca54a79f1facbd2bd48ab48a9bcd66f7cce919e0c3d906572c8eebc40f12f0b5e976a
6
+ metadata.gz: 4f59e9030add9d99fca4584f0b9181dd27ab7f5f65e778ce3f04ff238582dccf5fc17839578da58ba5d591b2dd44dd7c8705f38476170512ff7408821d5b17d3
7
+ data.tar.gz: 61a9c438dc4146c964d96b6358cc1545a47053e6d30fd4f9c7e02dc7773d4b2c85def3d8c805c26b44053d4dba9ad6b796442c93e8e5dc321df048a175b10879
data/CHANGELOG.md CHANGED
@@ -2,6 +2,21 @@
2
2
 
3
3
  All notable changes to `addressing` will be documented in this file.
4
4
 
5
+ ## 0.4.0 (13-07-2022)
6
+
7
+ - Update CLDR to v41
8
+
9
+ ## 0.3.1 (04-04-2022)
10
+
11
+ - Break with both subdivisions and parents when subdivision field is empty
12
+ - Only retrieve field if it exists on model
13
+
14
+ ## 0.3.0 (04-04-2022)
15
+
16
+ - Allow field validation to be overridden
17
+ - Only verify address when one of the field changes
18
+ - Allow used address fields to be configured
19
+
5
20
  ## 0.2.0 (25-02-2022)
6
21
 
7
22
  - Add ActiveRecord validations
data/README.md CHANGED
@@ -8,7 +8,7 @@ A Ruby addressing library, powered by CLDR and Google's address data.
8
8
  - Both latin and local subdivision names, when relevant (e.g: Okinawa / 沖縄県)
9
9
  - Formatting, both in HTML and plain text
10
10
 
11
- All data is [stored locally](data) as JSON and automatically updated through scheduled Github Actions. Countries are generated from [CLDR v40](https://github.com/unicode-org/cldr-json.git). Address formats and subdivisions are generated from [Google's Address Data Service](https://chromium-i18n.appspot.com/ssl-address).
11
+ All data is [stored locally](data) as JSON and automatically updated through scheduled Github Actions. Countries are generated from [CLDR v41](https://github.com/unicode-org/cldr-json.git). Address formats and subdivisions are generated from [Google's Address Data Service](https://chromium-i18n.appspot.com/ssl-address).
12
12
 
13
13
  [![Build Status](https://img.shields.io/github/workflow/status/robinvdvleuten/addressing/test.svg)](https://github.com/robinvdvleuten/addressing/actions?query=workflow%3Atest)
14
14
  [![MIT license](https://img.shields.io/github/license/robinvdvleuten/addressing.svg)](https://github.com/robinvdvleuten/addressing/blob/main/LICENSE)
@@ -182,6 +182,14 @@ class User < ApplicationRecord
182
182
  end
183
183
  ```
184
184
 
185
+ For performance, the address is only verified if at least one of the fields changes. Set your own condition with:
186
+
187
+ ```rb
188
+ class User < ApplicationRecord
189
+ validates_address if: -> { something_changed? }, ...
190
+ end
191
+ ```
192
+
185
193
  ## Changelog
186
194
 
187
195
  Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
@@ -0,0 +1,258 @@
1
+ {
2
+ "AF": "Afghanistan",
3
+ "AX": "Åland Islands",
4
+ "AL": "Albania",
5
+ "DZ": "Algeria",
6
+ "AS": "American Samoa",
7
+ "AD": "Andorra",
8
+ "AO": "Angola",
9
+ "AI": "Anguilla",
10
+ "AQ": "Antarctica",
11
+ "AG": "Antigua & Barbuda",
12
+ "AR": "Argentina",
13
+ "AM": "Armenia",
14
+ "AW": "Aruba",
15
+ "AC": "Ascension Island",
16
+ "AU": "Australia",
17
+ "AT": "Austria",
18
+ "AZ": "Azerbaijan",
19
+ "BS": "Bahamas",
20
+ "BH": "Bahrain",
21
+ "BD": "Bangladesh",
22
+ "BB": "Barbados",
23
+ "BY": "Belarus",
24
+ "BE": "Belgium",
25
+ "BZ": "Belize",
26
+ "BJ": "Benin",
27
+ "BM": "Bermuda",
28
+ "BT": "Bhutan",
29
+ "BO": "Bolivia",
30
+ "BA": "Bosnia & Herzegovina",
31
+ "BW": "Botswana",
32
+ "BV": "Bouvet Island",
33
+ "BR": "Brazil",
34
+ "IO": "British Indian Ocean Territory",
35
+ "VG": "British Virgin Islands",
36
+ "BN": "Brunei",
37
+ "BG": "Bulgaria",
38
+ "BF": "Burkina Faso",
39
+ "BI": "Burundi",
40
+ "KH": "Cambodia",
41
+ "CM": "Cameroon",
42
+ "CA": "Canada",
43
+ "IC": "Canary Islands",
44
+ "CV": "Cape Verde",
45
+ "BQ": "Caribbean Netherlands",
46
+ "KY": "Cayman Islands",
47
+ "CF": "Central African Republic",
48
+ "EA": "Ceuta & Melilla",
49
+ "TD": "Chad",
50
+ "CL": "Chile",
51
+ "CN": "China",
52
+ "CX": "Christmas Island",
53
+ "CP": "Clipperton Island",
54
+ "CC": "Cocos (Keeling) Islands",
55
+ "CO": "Colombia",
56
+ "KM": "Comoros",
57
+ "CG": "Congo - Brazzaville",
58
+ "CD": "Congo - Kinshasa",
59
+ "CK": "Cook Islands",
60
+ "CR": "Costa Rica",
61
+ "CI": "Côte d’Ivoire",
62
+ "HR": "Croatia",
63
+ "CU": "Cuba",
64
+ "CW": "Curaçao",
65
+ "CY": "Cyprus",
66
+ "CZ": "Czechia",
67
+ "DK": "Denmark",
68
+ "DG": "Diego Garcia",
69
+ "DJ": "Djibouti",
70
+ "DM": "Dominica",
71
+ "DO": "Dominican Republic",
72
+ "EC": "Ecuador",
73
+ "EG": "Egypt",
74
+ "SV": "El Salvador",
75
+ "GQ": "Equatorial Guinea",
76
+ "ER": "Eritrea",
77
+ "EE": "Estonia",
78
+ "SZ": "Eswatini",
79
+ "ET": "Ethiopia",
80
+ "FK": "Falkland Islands",
81
+ "FO": "Faroe Islands",
82
+ "FJ": "Fiji",
83
+ "FI": "Finland",
84
+ "FR": "France",
85
+ "GF": "French Guiana",
86
+ "PF": "French Polynesia",
87
+ "TF": "French Southern Territories",
88
+ "GA": "Gabon",
89
+ "GM": "Gambia",
90
+ "GE": "Georgia",
91
+ "DE": "Germany",
92
+ "GH": "Ghana",
93
+ "GI": "Gibraltar",
94
+ "GR": "Greece",
95
+ "GL": "Greenland",
96
+ "GD": "Grenada",
97
+ "GP": "Guadeloupe",
98
+ "GU": "Guam",
99
+ "GT": "Guatemala",
100
+ "GG": "Guernsey",
101
+ "GN": "Guinea",
102
+ "GW": "Guinea-Bissau",
103
+ "GY": "Guyana",
104
+ "HT": "Haiti",
105
+ "HM": "Heard & McDonald Islands",
106
+ "HN": "Honduras",
107
+ "HK": "Hong Kong SAR China",
108
+ "HU": "Hungary",
109
+ "IS": "Iceland",
110
+ "IN": "India",
111
+ "ID": "Indonesia",
112
+ "IR": "Iran",
113
+ "IQ": "Iraq",
114
+ "IE": "Ireland",
115
+ "IM": "Isle of Man",
116
+ "IL": "Israel",
117
+ "IT": "Italy",
118
+ "JM": "Jamaica",
119
+ "JP": "Japan",
120
+ "JE": "Jersey",
121
+ "JO": "Jordan",
122
+ "KZ": "Kazakhstan",
123
+ "KE": "Kenya",
124
+ "KI": "Kiribati",
125
+ "XK": "Kosovo",
126
+ "KW": "Kuwait",
127
+ "KG": "Kyrgyzstan",
128
+ "LA": "Laos",
129
+ "LV": "Latvia",
130
+ "LB": "Lebanon",
131
+ "LS": "Lesotho",
132
+ "LR": "Liberia",
133
+ "LY": "Libya",
134
+ "LI": "Liechtenstein",
135
+ "LT": "Lithuania",
136
+ "LU": "Luxembourg",
137
+ "MO": "Macao SAR China",
138
+ "MG": "Madagascar",
139
+ "MW": "Malawi",
140
+ "MY": "Malaysia",
141
+ "MV": "Maldives",
142
+ "ML": "Mali",
143
+ "MT": "Malta",
144
+ "MH": "Marshall Islands",
145
+ "MQ": "Martinique",
146
+ "MR": "Mauritania",
147
+ "MU": "Mauritius",
148
+ "YT": "Mayotte",
149
+ "MX": "Mexico",
150
+ "FM": "Micronesia",
151
+ "MD": "Moldova",
152
+ "MC": "Monaco",
153
+ "MN": "Mongolia",
154
+ "ME": "Montenegro",
155
+ "MS": "Montserrat",
156
+ "MA": "Morocco",
157
+ "MZ": "Mozambique",
158
+ "MM": "Myanmar (Burma)",
159
+ "NA": "Namibia",
160
+ "NR": "Nauru",
161
+ "NP": "Nepal",
162
+ "NL": "Netherlands",
163
+ "NC": "New Caledonia",
164
+ "NZ": "New Zealand",
165
+ "NI": "Nicaragua",
166
+ "NE": "Niger",
167
+ "NG": "Nigeria",
168
+ "NU": "Niue",
169
+ "NF": "Norfolk Island",
170
+ "KP": "North Korea",
171
+ "MK": "North Macedonia",
172
+ "MP": "Northern Mariana Islands",
173
+ "NO": "Norway",
174
+ "OM": "Oman",
175
+ "PK": "Pakistan",
176
+ "PW": "Palau",
177
+ "PS": "Palestinian Territories",
178
+ "PA": "Panama",
179
+ "PG": "Papua New Guinea",
180
+ "PY": "Paraguay",
181
+ "PE": "Peru",
182
+ "PH": "Philippines",
183
+ "PN": "Pitcairn Islands",
184
+ "PL": "Poland",
185
+ "PT": "Portugal",
186
+ "PR": "Puerto Rico",
187
+ "QA": "Qatar",
188
+ "RE": "Réunion",
189
+ "RO": "Romania",
190
+ "RU": "Russia",
191
+ "RW": "Rwanda",
192
+ "WS": "Samoa",
193
+ "SM": "San Marino",
194
+ "ST": "São Tomé & Príncipe",
195
+ "SA": "Saudi Arabia",
196
+ "SN": "Senegal",
197
+ "RS": "Serbia",
198
+ "SC": "Seychelles",
199
+ "SL": "Sierra Leone",
200
+ "SG": "Singapore",
201
+ "SX": "Sint Maarten",
202
+ "SK": "Slovakia",
203
+ "SI": "Slovenia",
204
+ "SB": "Solomon Islands",
205
+ "SO": "Somalia",
206
+ "ZA": "South Africa",
207
+ "GS": "South Georgia & South Sandwich Islands",
208
+ "KR": "South Korea",
209
+ "SS": "South Sudan",
210
+ "ES": "Spain",
211
+ "LK": "Sri Lanka",
212
+ "BL": "St. Barthélemy",
213
+ "SH": "St. Helena",
214
+ "KN": "St. Kitts & Nevis",
215
+ "LC": "St. Lucia",
216
+ "MF": "St. Martin",
217
+ "PM": "St. Pierre & Miquelon",
218
+ "VC": "St. Vincent & Grenadines",
219
+ "SD": "Sudan",
220
+ "SR": "Suriname",
221
+ "SJ": "Svalbard & Jan Mayen",
222
+ "SE": "Sweden",
223
+ "CH": "Switzerland",
224
+ "SY": "Syria",
225
+ "TW": "Taiwan",
226
+ "TJ": "Tajikistan",
227
+ "TZ": "Tanzania",
228
+ "TH": "Thailand",
229
+ "TL": "Timor-Leste",
230
+ "TG": "Togo",
231
+ "TK": "Tokelau",
232
+ "TO": "Tonga",
233
+ "TT": "Trinidad & Tobago",
234
+ "TA": "Tristan da Cunha",
235
+ "TN": "Tunisia",
236
+ "TR": "Turkey",
237
+ "TM": "Turkmenistan",
238
+ "TC": "Turks & Caicos Islands",
239
+ "TV": "Tuvalu",
240
+ "UG": "Uganda",
241
+ "UA": "Ukraine",
242
+ "AE": "United Arab Emirates",
243
+ "GB": "United Kingdom",
244
+ "US": "United States",
245
+ "UY": "Uruguay",
246
+ "UM": "US Outlying Islands",
247
+ "VI": "US Virgin Islands",
248
+ "UZ": "Uzbekistan",
249
+ "VU": "Vanuatu",
250
+ "VA": "Vatican City",
251
+ "VE": "Venezuela",
252
+ "VN": "Vietnam",
253
+ "WF": "Wallis & Futuna",
254
+ "EH": "Western Sahara",
255
+ "YE": "Yemen",
256
+ "ZM": "Zambia",
257
+ "ZW": "Zimbabwe"
258
+ }
@@ -0,0 +1,258 @@
1
+ {
2
+ "AF": "Afghanistan",
3
+ "AX": "Åland Islands",
4
+ "AL": "Albania",
5
+ "DZ": "Algeria",
6
+ "AS": "American Samoa",
7
+ "AD": "Andorra",
8
+ "AO": "Angola",
9
+ "AI": "Anguilla",
10
+ "AQ": "Antarctica",
11
+ "AG": "Antigua & Barbuda",
12
+ "AR": "Argentina",
13
+ "AM": "Armenia",
14
+ "AW": "Aruba",
15
+ "AC": "Ascension Island",
16
+ "AU": "Australia",
17
+ "AT": "Austria",
18
+ "AZ": "Azerbaijan",
19
+ "BS": "Bahamas",
20
+ "BH": "Bahrain",
21
+ "BD": "Bangladesh",
22
+ "BB": "Barbados",
23
+ "BY": "Belarus",
24
+ "BE": "Belgium",
25
+ "BZ": "Belize",
26
+ "BJ": "Benin",
27
+ "BM": "Bermuda",
28
+ "BT": "Bhutan",
29
+ "BO": "Bolivia",
30
+ "BA": "Bosnia & Herzegovina",
31
+ "BW": "Botswana",
32
+ "BV": "Bouvet Island",
33
+ "BR": "Brazil",
34
+ "IO": "British Indian Ocean Territory",
35
+ "VG": "British Virgin Islands",
36
+ "BN": "Brunei",
37
+ "BG": "Bulgaria",
38
+ "BF": "Burkina Faso",
39
+ "BI": "Burundi",
40
+ "KH": "Cambodia",
41
+ "CM": "Cameroon",
42
+ "CA": "Canada",
43
+ "IC": "Canary Islands",
44
+ "CV": "Cape Verde",
45
+ "BQ": "Caribbean Netherlands",
46
+ "KY": "Cayman Islands",
47
+ "CF": "Central African Republic",
48
+ "EA": "Ceuta & Melilla",
49
+ "TD": "Chad",
50
+ "CL": "Chile",
51
+ "CN": "China",
52
+ "CX": "Christmas Island",
53
+ "CP": "Clipperton Island",
54
+ "CC": "Cocos (Keeling) Islands",
55
+ "CO": "Colombia",
56
+ "KM": "Comoros",
57
+ "CG": "Congo - Brazzaville",
58
+ "CD": "Congo - Kinshasa",
59
+ "CK": "Cook Islands",
60
+ "CR": "Costa Rica",
61
+ "CI": "Côte d’Ivoire",
62
+ "HR": "Croatia",
63
+ "CU": "Cuba",
64
+ "CW": "Curaçao",
65
+ "CY": "Cyprus",
66
+ "CZ": "Czechia",
67
+ "DK": "Denmark",
68
+ "DG": "Diego Garcia",
69
+ "DJ": "Djibouti",
70
+ "DM": "Dominica",
71
+ "DO": "Dominican Republic",
72
+ "EC": "Ecuador",
73
+ "EG": "Egypt",
74
+ "SV": "El Salvador",
75
+ "GQ": "Equatorial Guinea",
76
+ "ER": "Eritrea",
77
+ "EE": "Estonia",
78
+ "SZ": "Eswatini",
79
+ "ET": "Ethiopia",
80
+ "FK": "Falkland Islands",
81
+ "FO": "Faroe Islands",
82
+ "FJ": "Fiji",
83
+ "FI": "Finland",
84
+ "FR": "France",
85
+ "GF": "French Guiana",
86
+ "PF": "French Polynesia",
87
+ "TF": "French Southern Territories",
88
+ "GA": "Gabon",
89
+ "GM": "Gambia",
90
+ "GE": "Georgia",
91
+ "DE": "Germany",
92
+ "GH": "Ghana",
93
+ "GI": "Gibraltar",
94
+ "GR": "Greece",
95
+ "GL": "Greenland",
96
+ "GD": "Grenada",
97
+ "GP": "Guadeloupe",
98
+ "GU": "Guam",
99
+ "GT": "Guatemala",
100
+ "GG": "Guernsey",
101
+ "GN": "Guinea",
102
+ "GW": "Guinea-Bissau",
103
+ "GY": "Guyana",
104
+ "HT": "Haiti",
105
+ "HM": "Heard & McDonald Islands",
106
+ "HN": "Honduras",
107
+ "HK": "Hong Kong SAR China",
108
+ "HU": "Hungary",
109
+ "IS": "Iceland",
110
+ "IN": "India",
111
+ "ID": "Indonesia",
112
+ "IR": "Iran",
113
+ "IQ": "Iraq",
114
+ "IE": "Ireland",
115
+ "IM": "Isle of Man",
116
+ "IL": "Israel",
117
+ "IT": "Italy",
118
+ "JM": "Jamaica",
119
+ "JP": "Japan",
120
+ "JE": "Jersey",
121
+ "JO": "Jordan",
122
+ "KZ": "Kazakhstan",
123
+ "KE": "Kenya",
124
+ "KI": "Kiribati",
125
+ "XK": "Kosovo",
126
+ "KW": "Kuwait",
127
+ "KG": "Kyrgyzstan",
128
+ "LA": "Laos",
129
+ "LV": "Latvia",
130
+ "LB": "Lebanon",
131
+ "LS": "Lesotho",
132
+ "LR": "Liberia",
133
+ "LY": "Libya",
134
+ "LI": "Liechtenstein",
135
+ "LT": "Lithuania",
136
+ "LU": "Luxembourg",
137
+ "MO": "Macao SAR China",
138
+ "MG": "Madagascar",
139
+ "MW": "Malawi",
140
+ "MY": "Malaysia",
141
+ "MV": "Maldives",
142
+ "ML": "Mali",
143
+ "MT": "Malta",
144
+ "MH": "Marshall Islands",
145
+ "MQ": "Martinique",
146
+ "MR": "Mauritania",
147
+ "MU": "Mauritius",
148
+ "YT": "Mayotte",
149
+ "MX": "Mexico",
150
+ "FM": "Micronesia",
151
+ "MD": "Moldova",
152
+ "MC": "Monaco",
153
+ "MN": "Mongolia",
154
+ "ME": "Montenegro",
155
+ "MS": "Montserrat",
156
+ "MA": "Morocco",
157
+ "MZ": "Mozambique",
158
+ "MM": "Myanmar (Burma)",
159
+ "NA": "Namibia",
160
+ "NR": "Nauru",
161
+ "NP": "Nepal",
162
+ "NL": "Netherlands",
163
+ "NC": "New Caledonia",
164
+ "NZ": "New Zealand",
165
+ "NI": "Nicaragua",
166
+ "NE": "Niger",
167
+ "NG": "Nigeria",
168
+ "NU": "Niue",
169
+ "NF": "Norfolk Island",
170
+ "KP": "North Korea",
171
+ "MK": "North Macedonia",
172
+ "MP": "Northern Mariana Islands",
173
+ "NO": "Norway",
174
+ "OM": "Oman",
175
+ "PK": "Pakistan",
176
+ "PW": "Palau",
177
+ "PS": "Palestinian Territories",
178
+ "PA": "Panama",
179
+ "PG": "Papua New Guinea",
180
+ "PY": "Paraguay",
181
+ "PE": "Peru",
182
+ "PH": "Philippines",
183
+ "PN": "Pitcairn Islands",
184
+ "PL": "Poland",
185
+ "PT": "Portugal",
186
+ "PR": "Puerto Rico",
187
+ "QA": "Qatar",
188
+ "RE": "Réunion",
189
+ "RO": "Romania",
190
+ "RU": "Russia",
191
+ "RW": "Rwanda",
192
+ "WS": "Samoa",
193
+ "SM": "San Marino",
194
+ "ST": "São Tomé & Príncipe",
195
+ "SA": "Saudi Arabia",
196
+ "SN": "Senegal",
197
+ "RS": "Serbia",
198
+ "SC": "Seychelles",
199
+ "SL": "Sierra Leone",
200
+ "SG": "Singapore",
201
+ "SX": "Sint Maarten",
202
+ "SK": "Slovakia",
203
+ "SI": "Slovenia",
204
+ "SB": "Solomon Islands",
205
+ "SO": "Somalia",
206
+ "ZA": "South Africa",
207
+ "GS": "South Georgia & South Sandwich Islands",
208
+ "KR": "South Korea",
209
+ "SS": "South Sudan",
210
+ "ES": "Spain",
211
+ "LK": "Sri Lanka",
212
+ "BL": "St. Barthélemy",
213
+ "SH": "St. Helena",
214
+ "KN": "St. Kitts & Nevis",
215
+ "LC": "St. Lucia",
216
+ "MF": "St. Martin",
217
+ "PM": "St. Pierre & Miquelon",
218
+ "VC": "St. Vincent & Grenadines",
219
+ "SD": "Sudan",
220
+ "SR": "Suriname",
221
+ "SJ": "Svalbard & Jan Mayen",
222
+ "SE": "Sweden",
223
+ "CH": "Switzerland",
224
+ "SY": "Syria",
225
+ "TW": "Taiwan",
226
+ "TJ": "Tajikistan",
227
+ "TZ": "Tanzania",
228
+ "TH": "Thailand",
229
+ "TL": "Timor-Leste",
230
+ "TG": "Togo",
231
+ "TK": "Tokelau",
232
+ "TO": "Tonga",
233
+ "TT": "Trinidad & Tobago",
234
+ "TA": "Tristan da Cunha",
235
+ "TN": "Tunisia",
236
+ "TR": "Turkey",
237
+ "TM": "Turkmenistan",
238
+ "TC": "Turks & Caicos Islands",
239
+ "TV": "Tuvalu",
240
+ "UM": "U.S. Outlying Islands",
241
+ "VI": "U.S. Virgin Islands",
242
+ "UG": "Uganda",
243
+ "UA": "Ukraine",
244
+ "AE": "United Arab Emirates",
245
+ "GB": "United Kingdom",
246
+ "US": "United States",
247
+ "UY": "Uruguay",
248
+ "UZ": "Uzbekistan",
249
+ "VU": "Vanuatu",
250
+ "VA": "Vatican City",
251
+ "VE": "Venezuela",
252
+ "VN": "Vietnam",
253
+ "WF": "Wallis & Futuna",
254
+ "EH": "Western Sahara",
255
+ "YE": "Yemen",
256
+ "ZM": "Zambia",
257
+ "ZW": "Zimbabwe"
258
+ }
data/data/country/zh.json CHANGED
@@ -35,6 +35,7 @@
35
35
  "MK": "北马其顿",
36
36
  "BJ": "贝宁",
37
37
  "BE": "比利时",
38
+ "PE": "秘鲁",
38
39
  "IS": "冰岛",
39
40
  "PR": "波多黎各",
40
41
  "PL": "波兰",
@@ -148,7 +149,6 @@
148
149
  "MN": "蒙古",
149
150
  "MS": "蒙特塞拉特",
150
151
  "BD": "孟加拉国",
151
- "PE": "秘鲁",
152
152
  "FM": "密克罗尼西亚",
153
153
  "MM": "缅甸",
154
154
  "MD": "摩尔多瓦",
@@ -7,12 +7,6 @@
7
7
  ],
8
8
  "locale": "zh-Hans",
9
9
  "subdivisions": {
10
- "Chenbei Xinqu": {
11
- "local_code": "沈北新区"
12
- },
13
- "Shenhe Qu": {
14
- "local_code": "沈河区"
15
- },
16
10
  "Dadong Qu": {
17
11
  "local_code": "大东区"
18
12
  },
@@ -35,6 +29,12 @@
35
29
  "Liaozhong Xian": {
36
30
  "local_code": "辽中县"
37
31
  },
32
+ "Chenbei Xinqu": {
33
+ "local_code": "沈北新区"
34
+ },
35
+ "Shenhe Qu": {
36
+ "local_code": "沈河区"
37
+ },
38
38
  "Sujiatun Qu": {
39
39
  "local_code": "苏家屯区"
40
40
  },
@@ -7,9 +7,6 @@
7
7
  ],
8
8
  "locale": "zh-Hans",
9
9
  "subdivisions": {
10
- "Shenqiu Xian": {
11
- "local_code": "沈丘县"
12
- },
13
10
  "Chuanhui Qu": {
14
11
  "local_code": "川汇区"
15
12
  },
@@ -28,6 +25,9 @@
28
25
  "Shangshui Xian": {
29
26
  "local_code": "商水县"
30
27
  },
28
+ "Shenqiu Xian": {
29
+ "local_code": "沈丘县"
30
+ },
31
31
  "Taikang Xian": {
32
32
  "local_code": "太康县"
33
33
  },
@@ -13,15 +13,15 @@
13
13
  "Chunhua Xian": {
14
14
  "local_code": "淳化县"
15
15
  },
16
- "Qian Xian": {
17
- "local_code": "乾县"
18
- },
19
16
  "Jingyang Xian": {
20
17
  "local_code": "泾阳县"
21
18
  },
22
19
  "Liquan Xian": {
23
20
  "local_code": "礼泉县"
24
21
  },
22
+ "Qian Xian": {
23
+ "local_code": "乾县"
24
+ },
25
25
  "Qindu Qu": {
26
26
  "local_code": "秦都区"
27
27
  },
@@ -109,7 +109,7 @@
109
109
  },
110
110
  "Xinzhuang District": {
111
111
  "local_code": "新莊區",
112
- "postal_code_pattern": "242"
112
+ "postal_code_pattern": "24[28]"
113
113
  },
114
114
  "Yingge District": {
115
115
  "local_code": "鶯歌區",
@@ -10,9 +10,6 @@
10
10
  "Fuyu Xian": {
11
11
  "local_code": "扶余县"
12
12
  },
13
- "Qian'an Xian": {
14
- "local_code": "乾安县"
15
- },
16
13
  "Ningjiang Qu": {
17
14
  "local_code": "宁江区"
18
15
  },
@@ -20,6 +17,9 @@
20
17
  "local_code": "前郭尔罗斯蒙古族自治县",
21
18
  "local_name": "前郭尔罗斯县"
22
19
  },
20
+ "Qian'an Xian": {
21
+ "local_code": "乾安县"
22
+ },
23
23
  "Changling Xian": {
24
24
  "local_code": "长岭县"
25
25
  }
@@ -21,7 +21,7 @@
21
21
  },
22
22
  "Heungdeok-gu": {
23
23
  "local_code": "흥덕구",
24
- "postal_code_pattern": "28[13-6]"
24
+ "postal_code_pattern": "28[1-6]"
25
25
  }
26
26
  }
27
27
  }
@@ -96,7 +96,7 @@
96
96
  },
97
97
  "Xinzhuang District": {
98
98
  "local_code": "新莊區",
99
- "postal_code_pattern": "242"
99
+ "postal_code_pattern": "24[28]"
100
100
  },
101
101
  "Ruifang District": {
102
102
  "local_code": "瑞芳區",
@@ -141,4 +141,25 @@ module Addressing
141
141
  fields & used_fields
142
142
  end
143
143
  end
144
+
145
+ class AddressFormatHelper
146
+ class << self
147
+ # Gets the required fields.
148
+ #
149
+ # Applies field overrides to the required fields
150
+ # specified by the address format.
151
+ def required_fields(address_format, field_overrides)
152
+ required_fields = address_format.required_fields
153
+ required_fields = required_fields - field_overrides.optional_fields
154
+ required_fields = required_fields - field_overrides.hidden_fields
155
+
156
+ if field_overrides.required_fields
157
+ required_fields = required_fields + field_overrides.required_fields
158
+ required_fields = required_fields.uniq
159
+ end
160
+
161
+ required_fields
162
+ end
163
+ end
164
+ end
144
165
  end
@@ -8,18 +8,18 @@ module Addressing
8
8
  @@available_locales = [
9
9
  "af", "am", "ar", "ar-LY", "ar-SA", "as", "az", "be", "bg", "bn",
10
10
  "bn-IN", "bs", "ca", "cs", "cy", "da", "de", "de-AT", "de-CH", "el",
11
- "en", "en-001", "en-CA", "en-GB", "es", "es-419", "es-AR",
11
+ "en", "en-001", "en-CA", "en-GB", "en-MV", "es", "es-419", "es-AR",
12
12
  "es-BO", "es-CL", "es-CO", "es-CR", "es-DO", "es-EC", "es-GT", "es-HN",
13
13
  "es-MX", "es-NI", "es-PA", "es-PE", "es-PR", "es-PY", "es-SV", "es-US",
14
14
  "es-VE", "et", "eu", "fa", "fa-AF", "fi", "fil", "fr", "fr-BE", "fr-CA",
15
- "ga", "gl", "gu", "he", "hi", "hr", "hu", "hy", "id", "is", "it", "ja",
16
- "ka", "kk", "km", "ko", "ko-KP", "ky", "lo", "lt", "lv", "mk", "ml",
17
- "mn", "mr", "ms", "my", "ne", "nl", "nn", "no", "or", "pa", "pl", "ps",
18
- "ps-PK", "pt", "pt-PT", "ro", "ro-MD", "ru", "ru-UA", "sd", "si", "sk",
19
- "sl", "so", "sq", "sr", "sr-Cyrl-BA", "sr-Cyrl-ME", "sr-Cyrl-XK",
20
- "sr-Latn", "sr-Latn-BA", "sr-Latn-ME", "sr-Latn-XK", "sv", "sw",
21
- "sw-CD", "sw-KE", "ta", "te", "th", "tk", "tr", "uk", "ur", "ur-IN",
22
- "uz", "vi", "yue", "zh", "zh-Hant", "zh-Hant-HK", "zu"
15
+ "ga", "gl", "gu", "he", "hi", "hi-Latn", "hr", "hu", "hy", "id", "is",
16
+ "it", "ja", "ka", "kk", "km", "ko", "ko-KP", "ky", "lo", "lt", "lv",
17
+ "mk", "ml", "mn", "mr", "ms", "my", "ne", "nl", "nn", "no", "or", "pa",
18
+ "pl", "ps", "ps-PK", "pt", "pt-PT", "ro", "ro-MD", "ru", "ru-UA", "sd",
19
+ "si", "sk", "sl", "so", "sq", "sr", "sr-Cyrl-BA", "sr-Cyrl-ME",
20
+ "sr-Cyrl-XK", "sr-Latn", "sr-Latn-BA", "sr-Latn-ME", "sr-Latn-XK", "sv",
21
+ "sw", "sw-CD", "sw-KE", "ta", "te", "th", "tk", "tr", "uk", "ur",
22
+ "ur-IN", "uz", "vi", "yue", "zh", "zh-Hant", "zh-Hant-HK", "zu"
23
23
  ]
24
24
 
25
25
  def get(country_code, locale = "en", fallback_locale = "en")
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Addressing
4
+ class FieldOverride < Enum
5
+ HIDDEN = "hidden"
6
+ OPTIONAL = "optional"
7
+ REQUIRED = "required"
8
+ end
9
+
10
+ class FieldOverrides
11
+ attr_reader :hidden_fields, :optional_fields, :required_fields
12
+
13
+ def initialize(definition)
14
+ AddressField.assert_all_exist(definition.keys)
15
+ FieldOverride.assert_all_exist(definition.values)
16
+
17
+ @hidden_fields = []
18
+ @optional_fields = []
19
+ @required_fields = []
20
+
21
+ definition.each do |field, override|
22
+ case override
23
+ when FieldOverride::HIDDEN
24
+ @hidden_fields << field
25
+ when FieldOverride::OPTIONAL
26
+ @optional_fields << field
27
+ when FieldOverride::REQUIRED
28
+ @required_fields << field
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -2,16 +2,20 @@
2
2
 
3
3
  module Addressing
4
4
  module Model
5
- def validates_address_format(**options)
5
+ def validates_address_format(
6
+ fields: [:country_code, :administrative_area, :locality, :dependent_locality, :postal_code, :sorting_code, :address_line1, :address_line2, :organization, :given_name, :additional_name, :family_name, :locale], field_overrides: nil, **options)
7
+ fields = Array(fields)
8
+ field_overrides ||= FieldOverrides.new({})
9
+
10
+ options[:if] ||= -> { fields.any? { |f| changes.key?(f.to_s) } } unless options[:unless]
11
+
6
12
  class_eval do
7
13
  validate :verify_address_format, **options
8
14
 
9
15
  define_method :verify_address_format do
10
- fields = [:country_code, :administrative_area, :locality, :dependent_locality, :postal_code, :sorting_code, :address_line1, :address_line2, :organization, :given_name, :additional_name, :family_name, :locale].each_with_object({}) do |field, fields|
11
- fields[field] = send(field)
12
- end
16
+ values = fields.each_with_object({}) { |f, v| v[f] = send(f) if self.respond_to?(f) }
17
+ address = Address.new(**values)
13
18
 
14
- address = Address.new(**fields)
15
19
  return unless address.country_code.present?
16
20
 
17
21
  address_format = AddressFormat.get(address.country_code)
@@ -23,14 +27,16 @@ module Addressing
23
27
  address_format.used_fields
24
28
 
25
29
  # Validate the presence of required fields.
26
- address_format.required_fields.each do |required_field|
30
+ AddressFormatHelper::required_fields(address_format, field_overrides).each do |required_field|
27
31
  next unless address.send(required_field).blank?
28
32
 
29
33
  errors.add(required_field, "should not be blank")
30
34
  end
31
35
 
36
+ used_fields = address_format.used_fields - field_overrides.hidden_fields
37
+
32
38
  # Validate the absence of unused fields.
33
- unused_fields = AddressField.all.values - address_format.used_fields
39
+ unused_fields = AddressField.all.values - used_fields
34
40
  unused_fields.each do |unused_field|
35
41
  next if address.send(unused_field).blank?
36
42
 
@@ -38,20 +44,19 @@ module Addressing
38
44
  end
39
45
 
40
46
  # Validate subdivisions.
41
- subdivisions = verify_subdivisions(address, address_format)
47
+ subdivisions = verify_subdivisions(address, address_format, field_overrides)
42
48
 
43
49
  # Validate postal code.
44
- verify_postal_code(address.postal_code, subdivisions, address_format) if address_format.used_fields.include?(AddressField::POSTAL_CODE)
50
+ verify_postal_code(address.postal_code, subdivisions, address_format) if used_fields.include?(AddressField::POSTAL_CODE)
45
51
  end
46
52
 
47
- define_method :verify_subdivisions do |address, address_format|
53
+ define_method :verify_subdivisions do |address, address_format, field_overrides|
48
54
  # No predefined subdivisions exist, nothing to validate against.
49
55
  return [] if address_format.subdivision_depth < 1
50
56
 
51
57
  subdivisions, _parents = address_format.used_subdivision_fields.each_with_index.inject([[], []]) do |(subdivisions, parents), (field, index)|
52
58
  # The field is empty or validation is disabled.
53
- # break subdivisions if address.send(field).blank? || address_format.hidden_fields.include?(field)
54
- break subdivisions if address.send(field).blank?
59
+ break [subdivisions, parents] if address.send(field).blank? || field_overrides.hidden_fields.include?(field)
55
60
 
56
61
  parents << (index > 0 ? address.send(address_format.used_subdivision_fields[index - 1]) : address_format.country_code)
57
62
  subdivision = Subdivision.get(address.send(field), parents)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Addressing
4
- VERSION = "0.2.0"
4
+ VERSION = "0.4.0"
5
5
  end
data/lib/addressing.rb CHANGED
@@ -12,6 +12,7 @@ require "addressing/administrative_area_type"
12
12
  require "addressing/country"
13
13
  require "addressing/default_formatter"
14
14
  require "addressing/dependent_locality_type"
15
+ require "addressing/field_override"
15
16
  require "addressing/lazy_subdivisions"
16
17
  require "addressing/locale"
17
18
  require "addressing/locality_type"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: addressing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robin van der Vleuten
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-25 00:00:00.000000000 Z
11
+ date: 2022-07-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: robinvdvleuten@gmail.com
@@ -44,6 +44,7 @@ files:
44
44
  - data/country/en-001.json
45
45
  - data/country/en-CA.json
46
46
  - data/country/en-GB.json
47
+ - data/country/en-MV.json
47
48
  - data/country/en.json
48
49
  - data/country/es-419.json
49
50
  - data/country/es-AR.json
@@ -78,6 +79,7 @@ files:
78
79
  - data/country/gl.json
79
80
  - data/country/gu.json
80
81
  - data/country/he.json
82
+ - data/country/hi-Latn.json
81
83
  - data/country/hi.json
82
84
  - data/country/hr.json
83
85
  - data/country/hu.json
@@ -689,6 +691,7 @@ files:
689
691
  - lib/addressing/default_formatter.rb
690
692
  - lib/addressing/dependent_locality_type.rb
691
693
  - lib/addressing/enum.rb
694
+ - lib/addressing/field_override.rb
692
695
  - lib/addressing/lazy_subdivisions.rb
693
696
  - lib/addressing/locale.rb
694
697
  - lib/addressing/locality_type.rb