addressing 1.1.0 → 2.1.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 +4 -4
- data/CHANGELOG.md +27 -0
- data/README.md +3 -2
- data/data/address_formats.dump +0 -0
- data/data/address_formats.json +64 -64
- data/data/country/af.json +1 -1
- data/data/country/ak.json +258 -0
- data/data/country/am.json +18 -18
- data/data/country/ba.json +258 -0
- data/data/country/bn-IN.json +3 -3
- data/data/country/bn.json +3 -3
- data/data/country/bs.json +1 -0
- data/data/country/ca.json +9 -9
- data/data/country/cv.json +258 -0
- data/data/country/cy.json +1 -1
- data/data/country/en-AU.json +16 -16
- data/data/country/en-LT.json +258 -0
- data/data/country/en-LV.json +258 -0
- data/data/country/en-UA.json +258 -0
- data/data/country/fil.json +1 -1
- data/data/country/fr-CA.json +1 -1
- data/data/country/ga.json +17 -17
- data/data/country/gd.json +2 -2
- data/data/country/gl.json +20 -20
- data/data/country/gu.json +12 -12
- data/data/country/hr.json +17 -17
- data/data/country/hy.json +2 -2
- data/data/country/ig.json +30 -30
- data/data/country/is.json +1 -1
- data/data/country/it.json +8 -8
- data/data/country/kk-Arab.json +258 -0
- data/data/country/kok.json +158 -158
- data/data/country/ky.json +3 -3
- data/data/country/lt.json +1 -1
- data/data/country/lv.json +9 -9
- data/data/country/mk.json +1 -1
- data/data/country/ml.json +1 -1
- data/data/country/mn.json +9 -9
- data/data/country/mr.json +1 -1
- data/data/country/or.json +14 -14
- data/data/country/pa.json +7 -7
- data/data/country/qu.json +258 -0
- data/data/country/rm.json +258 -0
- data/data/country/shn.json +258 -0
- data/data/country/sl.json +16 -16
- data/data/country/so.json +2 -2
- data/data/country/sr-Cyrl-BA.json +1 -1
- data/data/country/sr-Cyrl-ME.json +1 -1
- data/data/country/sr-Cyrl-XK.json +1 -1
- data/data/country/sr-Latn-BA.json +1 -1
- data/data/country/sr-Latn-ME.json +1 -1
- data/data/country/sr-Latn-XK.json +1 -1
- data/data/country/sr-Latn.json +1 -1
- data/data/country/sr.json +1 -1
- data/data/country/sw-CD.json +1 -1
- data/data/country/sw.json +1 -1
- data/data/country/ta.json +3 -3
- data/data/country/te.json +11 -11
- data/data/country/vi.json +1 -1
- data/data/country/yue-Hans.json +11 -11
- data/data/country/yue.json +10 -10
- data/data/subdivision/AE.json +1 -1
- data/data/subdivision/CA.json +6 -12
- data/data/subdivision/CO.json +1 -1
- data/data/subdivision/GB.json +675 -0
- data/data/subdivision/GT.json +71 -0
- data/data/subdivision/IT.json +13 -1
- data/data/subdivision/NG.json +1 -1
- data/data/subdivision/RU.json +4 -4
- data/data/subdivision/TH.json +7 -7
- data/data/subdivision/TR.json +1 -1
- data/data/subdivision/VE.json +4 -4
- data/data/subdivision/VN.json +38 -154
- data/lib/addressing/address_format.rb +38 -16
- data/lib/addressing/country.rb +21 -19
- data/lib/addressing/default_formatter.rb +40 -12
- data/lib/addressing/locale.rb +24 -11
- data/lib/addressing/model.rb +9 -10
- data/lib/addressing/subdivision.rb +25 -7
- data/lib/addressing/version.rb +1 -1
- metadata +22 -6
- /data/data/country/{en-ID.json → en-EE.json} +0 -0
- /data/data/country/{en-MV.json → en-GE.json} +0 -0
data/lib/addressing/country.rb
CHANGED
|
@@ -18,21 +18,23 @@ module Addressing
|
|
|
18
18
|
class Country
|
|
19
19
|
class << self
|
|
20
20
|
AVAILABLE_LOCALES = [
|
|
21
|
-
"af", "am", "ar", "ar-LY", "ar-SA", "as", "az", "
|
|
22
|
-
"bn-IN", "bs", "ca", "chr", "cs", "
|
|
23
|
-
"
|
|
24
|
-
"en-
|
|
25
|
-
"es-
|
|
26
|
-
"es-
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
21
|
+
"af", "ak", "am", "ar", "ar-LY", "ar-SA", "as", "az", "ba", "be", "bg",
|
|
22
|
+
"bn", "bn-IN", "bs", "ca", "chr", "cs", "cv", "cy", "da", "de",
|
|
23
|
+
"de-AT", "de-CH", "dsb", "el", "el-polyton", "en", "en-001", "en-AU",
|
|
24
|
+
"en-CA", "en-EE", "en-GE", "en-LT", "en-LV", "en-UA", "es", "es-419",
|
|
25
|
+
"es-AR", "es-BO", "es-CL", "es-CO", "es-CR", "es-DO", "es-EC", "es-GT",
|
|
26
|
+
"es-HN", "es-MX", "es-NI", "es-PA", "es-PE", "es-PR", "es-PY", "es-SV",
|
|
27
|
+
"es-US", "es-VE", "et", "eu", "fa", "fa-AF", "fi", "fil", "fr",
|
|
28
|
+
"fr-BE", "fr-CA", "ga", "gd", "gl", "gu", "he", "hi", "hi-Latn", "hr",
|
|
29
|
+
"hsb", "hu", "hy", "id", "ig", "is", "it", "ja", "ka", "kk", "kk-Arab",
|
|
30
|
+
"km", "ko", "ko-KP", "kok", "ky", "lo", "lt", "lv", "mk", "ml", "mn",
|
|
31
|
+
"mr", "ms", "my", "ne", "nl", "nn", "no", "or", "pa", "pl", "ps",
|
|
32
|
+
"ps-PK", "pt", "pt-PT", "qu", "rm", "ro", "ro-MD", "ru", "ru-UA",
|
|
33
|
+
"shn", "si", "sk", "sl", "so", "sq", "sr", "sr-Cyrl-BA", "sr-Cyrl-ME",
|
|
34
|
+
"sr-Cyrl-XK", "sr-Latn", "sr-Latn-BA", "sr-Latn-ME", "sr-Latn-XK",
|
|
35
|
+
"sv", "sw", "sw-CD", "sw-KE", "ta", "te", "th", "tk", "tr", "uk", "ur",
|
|
36
|
+
"ur-IN", "uz", "vi", "yue", "yue-Hans", "zh", "zh-Hant", "zh-Hant-HK",
|
|
37
|
+
"zu"
|
|
36
38
|
]
|
|
37
39
|
|
|
38
40
|
# Gets a Country instance for the provided country code.
|
|
@@ -137,7 +139,7 @@ module Addressing
|
|
|
137
139
|
"BD" => ["BGD", "050", "BDT"],
|
|
138
140
|
"BE" => ["BEL", "056", "EUR"],
|
|
139
141
|
"BF" => ["BFA", "854", "XOF"],
|
|
140
|
-
"BG" => ["BGR", "100", "
|
|
142
|
+
"BG" => ["BGR", "100", "EUR"],
|
|
141
143
|
"BH" => ["BHR", "048", "BHD"],
|
|
142
144
|
"BI" => ["BDI", "108", "BIF"],
|
|
143
145
|
"BJ" => ["BEN", "204", "XOF"],
|
|
@@ -264,7 +266,7 @@ module Addressing
|
|
|
264
266
|
"MG" => ["MDG", "450", "MGA"],
|
|
265
267
|
"MH" => ["MHL", "584", "USD"],
|
|
266
268
|
"MK" => ["MKD", "807", "MKD"],
|
|
267
|
-
"ML" => ["MLI", "466",
|
|
269
|
+
"ML" => ["MLI", "466", nil],
|
|
268
270
|
"MM" => ["MMR", "104", "MMK"],
|
|
269
271
|
"MN" => ["MNG", "496", "MNT"],
|
|
270
272
|
"MO" => ["MAC", "446", "MOP"],
|
|
@@ -302,7 +304,7 @@ module Addressing
|
|
|
302
304
|
"PM" => ["SPM", "666", "EUR"],
|
|
303
305
|
"PN" => ["PCN", "612", "NZD"],
|
|
304
306
|
"PR" => ["PRI", "630", "USD"],
|
|
305
|
-
"PS" => ["PSE", "275", "
|
|
307
|
+
"PS" => ["PSE", "275", "ILS"],
|
|
306
308
|
"PT" => ["PRT", "620", "EUR"],
|
|
307
309
|
"PW" => ["PLW", "585", "USD"],
|
|
308
310
|
"PY" => ["PRY", "600", "PYG"],
|
|
@@ -370,7 +372,7 @@ module Addressing
|
|
|
370
372
|
"YT" => ["MYT", "175", "EUR"],
|
|
371
373
|
"ZA" => ["ZAF", "710", "ZAR"],
|
|
372
374
|
"ZM" => ["ZMB", "894", "ZMW"],
|
|
373
|
-
"ZW" => ["ZWE", "716", "
|
|
375
|
+
"ZW" => ["ZWE", "716", "ZWG"]
|
|
374
376
|
}
|
|
375
377
|
end
|
|
376
378
|
end
|
|
@@ -4,6 +4,7 @@ module Addressing
|
|
|
4
4
|
class DefaultFormatter
|
|
5
5
|
DEFAULT_LOCALE = "en"
|
|
6
6
|
FORMAT_PLACEHOLDER_PATTERN = /%[a-z1-9_]+/
|
|
7
|
+
FORMAT_SPLIT_PATTERN = /(#{FORMAT_PLACEHOLDER_PATTERN})/
|
|
7
8
|
LEADING_TRAILING_PUNCTUATION_PATTERN = /\A[ \-,]+|[ \-,]+\z/
|
|
8
9
|
MULTIPLE_SPACES_PATTERN = /\s\s+/
|
|
9
10
|
|
|
@@ -39,7 +40,7 @@ module Addressing
|
|
|
39
40
|
view = render_view(view)
|
|
40
41
|
|
|
41
42
|
replacements = view.map { |key, element| ["%#{key}", element] }.to_h
|
|
42
|
-
output = format_string
|
|
43
|
+
output = insert_values(format_string, replacements)
|
|
43
44
|
output = clean_output(output)
|
|
44
45
|
|
|
45
46
|
if options[:html]
|
|
@@ -99,6 +100,39 @@ module Addressing
|
|
|
99
100
|
end.join(" ")
|
|
100
101
|
end
|
|
101
102
|
|
|
103
|
+
# Inserts the rendered address fields into the format string.
|
|
104
|
+
#
|
|
105
|
+
# Empty fields need special handling. When one falls between two values,
|
|
106
|
+
# keep the separator before it and discard the one after it.
|
|
107
|
+
def insert_values(format_string, replacements)
|
|
108
|
+
format_string.split("\n", -1).map do |line|
|
|
109
|
+
rendered = +""
|
|
110
|
+
separator = ""
|
|
111
|
+
skipped = false
|
|
112
|
+
|
|
113
|
+
line.split(FORMAT_SPLIT_PATTERN, -1).each do |part|
|
|
114
|
+
unless replacements.key?(part)
|
|
115
|
+
# A separator before an empty field usually belongs to
|
|
116
|
+
# the value that came before it, so keep that one.
|
|
117
|
+
separator = part unless skipped
|
|
118
|
+
next
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
if replacements[part].empty?
|
|
122
|
+
skipped = true
|
|
123
|
+
next
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
rendered << separator if !rendered.empty? || !skipped
|
|
127
|
+
rendered << replacements[part]
|
|
128
|
+
separator = ""
|
|
129
|
+
skipped = false
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
rendered
|
|
133
|
+
end.join("\n")
|
|
134
|
+
end
|
|
135
|
+
|
|
102
136
|
# Removes empty lines, leading punctuation, excess whitespace.
|
|
103
137
|
def clean_output(output)
|
|
104
138
|
output.split("\n").map { |line| line.gsub(LEADING_TRAILING_PUNCTUATION_PATTERN, "").strip.gsub(MULTIPLE_SPACES_PATTERN, " ") }.reject(&:empty?).join("\n")
|
|
@@ -116,22 +150,18 @@ module Addressing
|
|
|
116
150
|
AddressField.all.map { |_, field| [field, address.send(field)] }.to_h
|
|
117
151
|
end
|
|
118
152
|
|
|
119
|
-
#
|
|
153
|
+
# Replaces the subdivision values with the codes of any predefined ones.
|
|
120
154
|
def resolve_subdivision_values(values, address, address_format)
|
|
121
|
-
|
|
155
|
+
parents = [address.country_code]
|
|
122
156
|
|
|
123
|
-
|
|
124
|
-
subdivision_fields.each_with_index.inject([{}, []]) do |(original_values, parents), (field, index)|
|
|
157
|
+
address_format.subdivision_fields.each do |field|
|
|
125
158
|
# This level is empty, so there can be no sublevels.
|
|
126
|
-
break if values[field].nil?
|
|
127
|
-
|
|
128
|
-
parents << ((index > 0) ? original_values[subdivision_fields[index - 1]] : address.country_code)
|
|
159
|
+
break if values[field].nil? || values[field].empty?
|
|
129
160
|
|
|
130
161
|
subdivision = Subdivision.get(values[field], parents)
|
|
131
162
|
break if subdivision.nil?
|
|
132
163
|
|
|
133
|
-
|
|
134
|
-
original_values[field] = values[field]
|
|
164
|
+
parents << values[field]
|
|
135
165
|
|
|
136
166
|
# Replace the value with the expected code.
|
|
137
167
|
use_local_name = Locale.match_candidates(address.locale, subdivision.locale)
|
|
@@ -139,8 +169,6 @@ module Addressing
|
|
|
139
169
|
|
|
140
170
|
# The current subdivision has no children, stop.
|
|
141
171
|
break unless subdivision.children?
|
|
142
|
-
|
|
143
|
-
[original_values, parents]
|
|
144
172
|
end
|
|
145
173
|
end
|
|
146
174
|
|
data/lib/addressing/locale.rb
CHANGED
|
@@ -52,36 +52,49 @@ module Addressing
|
|
|
52
52
|
"en-150" => "en-001",
|
|
53
53
|
"en-AG" => "en-001",
|
|
54
54
|
"en-AI" => "en-001",
|
|
55
|
+
"en-AT" => "en-150",
|
|
55
56
|
"en-AU" => "en-001",
|
|
56
57
|
"en-BB" => "en-001",
|
|
58
|
+
"en-BE" => "en-150",
|
|
57
59
|
"en-BM" => "en-001",
|
|
58
60
|
"en-BS" => "en-001",
|
|
59
61
|
"en-BW" => "en-001",
|
|
60
62
|
"en-BZ" => "en-001",
|
|
61
63
|
"en-CC" => "en-001",
|
|
64
|
+
"en-CH" => "en-150",
|
|
62
65
|
"en-CK" => "en-001",
|
|
63
66
|
"en-CM" => "en-001",
|
|
64
67
|
"en-CX" => "en-001",
|
|
65
68
|
"en-CY" => "en-001",
|
|
69
|
+
"en-CZ" => "en-150",
|
|
70
|
+
"en-DE" => "en-150",
|
|
66
71
|
"en-DG" => "en-001",
|
|
72
|
+
"en-DK" => "en-150",
|
|
67
73
|
"en-DM" => "en-001",
|
|
68
74
|
"en-ER" => "en-001",
|
|
75
|
+
"en-ES" => "en-150",
|
|
76
|
+
"en-FI" => "en-150",
|
|
69
77
|
"en-FJ" => "en-001",
|
|
70
78
|
"en-FK" => "en-001",
|
|
71
79
|
"en-FM" => "en-001",
|
|
80
|
+
"en-FR" => "en-150",
|
|
72
81
|
"en-GB" => "en-001",
|
|
73
82
|
"en-GD" => "en-001",
|
|
74
83
|
"en-GG" => "en-001",
|
|
75
84
|
"en-GH" => "en-001",
|
|
76
85
|
"en-GI" => "en-001",
|
|
77
86
|
"en-GM" => "en-001",
|
|
87
|
+
"en-GS" => "en-001",
|
|
78
88
|
"en-GY" => "en-001",
|
|
79
89
|
"en-HK" => "en-001",
|
|
90
|
+
"en-HU" => "en-150",
|
|
91
|
+
"en-ID" => "en-001",
|
|
80
92
|
"en-IE" => "en-001",
|
|
81
93
|
"en-IL" => "en-001",
|
|
82
94
|
"en-IM" => "en-001",
|
|
83
95
|
"en-IN" => "en-001",
|
|
84
96
|
"en-IO" => "en-001",
|
|
97
|
+
"en-IT" => "en-150",
|
|
85
98
|
"en-JE" => "en-001",
|
|
86
99
|
"en-JM" => "en-001",
|
|
87
100
|
"en-KE" => "en-001",
|
|
@@ -96,24 +109,33 @@ module Addressing
|
|
|
96
109
|
"en-MS" => "en-001",
|
|
97
110
|
"en-MT" => "en-001",
|
|
98
111
|
"en-MU" => "en-001",
|
|
112
|
+
"en-MV" => "en-001",
|
|
99
113
|
"en-MW" => "en-001",
|
|
100
114
|
"en-MY" => "en-001",
|
|
101
115
|
"en-NA" => "en-001",
|
|
102
116
|
"en-NF" => "en-001",
|
|
103
117
|
"en-NG" => "en-001",
|
|
118
|
+
"en-NL" => "en-150",
|
|
119
|
+
"en-NO" => "en-150",
|
|
104
120
|
"en-NR" => "en-001",
|
|
105
121
|
"en-NU" => "en-001",
|
|
106
122
|
"en-NZ" => "en-001",
|
|
107
123
|
"en-PG" => "en-001",
|
|
108
124
|
"en-PK" => "en-001",
|
|
125
|
+
"en-PL" => "en-150",
|
|
109
126
|
"en-PN" => "en-001",
|
|
127
|
+
"en-PT" => "en-150",
|
|
110
128
|
"en-PW" => "en-001",
|
|
129
|
+
"en-RO" => "en-150",
|
|
111
130
|
"en-RW" => "en-001",
|
|
112
131
|
"en-SB" => "en-001",
|
|
113
132
|
"en-SC" => "en-001",
|
|
114
133
|
"en-SD" => "en-001",
|
|
134
|
+
"en-SE" => "en-150",
|
|
115
135
|
"en-SG" => "en-001",
|
|
116
136
|
"en-SH" => "en-001",
|
|
137
|
+
"en-SI" => "en-150",
|
|
138
|
+
"en-SK" => "en-150",
|
|
117
139
|
"en-SL" => "en-001",
|
|
118
140
|
"en-SS" => "en-001",
|
|
119
141
|
"en-SX" => "en-001",
|
|
@@ -132,15 +154,6 @@ module Addressing
|
|
|
132
154
|
"en-ZA" => "en-001",
|
|
133
155
|
"en-ZM" => "en-001",
|
|
134
156
|
"en-ZW" => "en-001",
|
|
135
|
-
"en-AT" => "en-150",
|
|
136
|
-
"en-BE" => "en-150",
|
|
137
|
-
"en-CH" => "en-150",
|
|
138
|
-
"en-DE" => "en-150",
|
|
139
|
-
"en-DK" => "en-150",
|
|
140
|
-
"en-FI" => "en-150",
|
|
141
|
-
"en-NL" => "en-150",
|
|
142
|
-
"en-SE" => "en-150",
|
|
143
|
-
"en-SI" => "en-150",
|
|
144
157
|
"es-AR" => "es-419",
|
|
145
158
|
"es-BO" => "es-419",
|
|
146
159
|
"es-BR" => "es-419",
|
|
@@ -163,12 +176,13 @@ module Addressing
|
|
|
163
176
|
"es-US" => "es-419",
|
|
164
177
|
"es-UY" => "es-419",
|
|
165
178
|
"es-VE" => "es-419",
|
|
179
|
+
"hi-Latn" => "und",
|
|
180
|
+
"ht" => "fr-HT",
|
|
166
181
|
"nb" => "no",
|
|
167
182
|
"nn" => "no",
|
|
168
183
|
"pt-AO" => "pt-PT",
|
|
169
184
|
"pt-CH" => "pt-PT",
|
|
170
185
|
"pt-CV" => "pt-PT",
|
|
171
|
-
"pt-FR" => "pt-PT",
|
|
172
186
|
"pt-GQ" => "pt-PT",
|
|
173
187
|
"pt-GW" => "pt-PT",
|
|
174
188
|
"pt-LU" => "pt-PT",
|
|
@@ -184,7 +198,6 @@ module Addressing
|
|
|
184
198
|
"byn-Latn" => "und",
|
|
185
199
|
"en-Dsrt" => "und",
|
|
186
200
|
"en-Shaw" => "und",
|
|
187
|
-
"hi-Latn" => "und",
|
|
188
201
|
"iu-Latn" => "und",
|
|
189
202
|
"kk-Arab" => "und",
|
|
190
203
|
"ks-Deva" => "und",
|
data/lib/addressing/model.rb
CHANGED
|
@@ -46,25 +46,24 @@ module Addressing
|
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
define_method :verify_subdivisions do |address, address_format, field_overrides|
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
parents = [address_format.country_code]
|
|
50
|
+
subdivisions = []
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
address_format.subdivision_fields.each do |field|
|
|
53
|
+
value = address.send(field)
|
|
53
54
|
# The field is empty or validation is disabled.
|
|
54
|
-
break
|
|
55
|
+
break if value.blank? || field_overrides.hidden_fields.include?(field)
|
|
55
56
|
|
|
56
|
-
|
|
57
|
-
subdivision = Subdivision.get(address.send(field), parents)
|
|
57
|
+
subdivision = Subdivision.get(value, parents)
|
|
58
58
|
if subdivision.nil?
|
|
59
59
|
errors.add(field, "should be valid")
|
|
60
|
-
break
|
|
60
|
+
break
|
|
61
61
|
end
|
|
62
62
|
|
|
63
|
+
parents << value
|
|
63
64
|
subdivisions << subdivision
|
|
64
65
|
# No predefined subdivisions below this level, stop here.
|
|
65
|
-
break
|
|
66
|
-
|
|
67
|
-
[subdivisions, parents]
|
|
66
|
+
break unless subdivision.children?
|
|
68
67
|
end
|
|
69
68
|
|
|
70
69
|
subdivisions
|
|
@@ -58,8 +58,8 @@ module Addressing
|
|
|
58
58
|
def has_data(parents)
|
|
59
59
|
country_code = parents[0]
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
return false if
|
|
61
|
+
subdivision_fields = AddressFormat.get(country_code).subdivision_fields
|
|
62
|
+
return false if subdivision_fields.empty?
|
|
63
63
|
|
|
64
64
|
if parents.size > 1
|
|
65
65
|
# After the first level it is possible for predefined subdivisions
|
|
@@ -74,8 +74,9 @@ module Addressing
|
|
|
74
74
|
definition = @definitions[parent_group]["subdivisions"][parent_id]
|
|
75
75
|
return !!definition["has_children"]
|
|
76
76
|
else
|
|
77
|
-
# The parent definition wasn't loaded previously, fallback to
|
|
78
|
-
|
|
77
|
+
# The parent definition wasn't loaded previously, fallback to
|
|
78
|
+
# guessing based on the count of subdivision data fields.
|
|
79
|
+
return parents.size <= subdivision_fields.size
|
|
79
80
|
end
|
|
80
81
|
end
|
|
81
82
|
|
|
@@ -98,19 +99,30 @@ module Addressing
|
|
|
98
99
|
filename = File.join(File.expand_path("../../../data/subdivision", __FILE__).to_s, "#{group}.json")
|
|
99
100
|
|
|
100
101
|
if File.exist?(filename)
|
|
101
|
-
|
|
102
|
-
@definitions[group] = JSON.parse(raw_definition)
|
|
103
|
-
@definitions[group] = process_definitions(@definitions[group])
|
|
102
|
+
@definitions[group] = process_definitions(parse_definitions(File.read(filename)))
|
|
104
103
|
end
|
|
105
104
|
end
|
|
106
105
|
|
|
107
106
|
@definitions[group]
|
|
108
107
|
end
|
|
109
108
|
|
|
109
|
+
# Parses a raw definition file.
|
|
110
|
+
#
|
|
111
|
+
# Malformed JSON is treated as if the file didn't exist.
|
|
112
|
+
def parse_definitions(raw_definition)
|
|
113
|
+
definitions = JSON.parse(raw_definition)
|
|
114
|
+
definitions.is_a?(Hash) ? definitions : {}
|
|
115
|
+
rescue JSON::ParserError
|
|
116
|
+
{}
|
|
117
|
+
end
|
|
118
|
+
|
|
110
119
|
# Processes the loaded definitions.
|
|
111
120
|
#
|
|
112
121
|
# Adds keys and values that were removed from the JSON files for brevity.
|
|
113
122
|
def process_definitions(definitions)
|
|
123
|
+
# Malformed definitions are treated as if they didn't exist.
|
|
124
|
+
return {} unless definitions["subdivisions"].is_a?(Hash)
|
|
125
|
+
|
|
114
126
|
definitions["subdivisions"].each do |id, definition|
|
|
115
127
|
# Add common keys from the root level.
|
|
116
128
|
definition["country_code"] = definitions["country_code"]
|
|
@@ -124,6 +136,12 @@ module Addressing
|
|
|
124
136
|
definition["name"] = id
|
|
125
137
|
end
|
|
126
138
|
|
|
139
|
+
# The local_name value is only specified if it doesn't match
|
|
140
|
+
# the name one.
|
|
141
|
+
if definitions.key?("locale") && !definition.key?("local_name")
|
|
142
|
+
definition["local_name"] = definition["name"]
|
|
143
|
+
end
|
|
144
|
+
|
|
127
145
|
# The code and local_code values are only specified if they
|
|
128
146
|
# don't match the name and local_name ones.
|
|
129
147
|
if !definition.key?("code") && definition.key?("name")
|
data/lib/addressing/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: addressing
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Robin van der Vleuten
|
|
8
|
+
autorequire:
|
|
8
9
|
bindir: bin
|
|
9
10
|
cert_chain: []
|
|
10
|
-
date:
|
|
11
|
+
date: 2026-09-18 00:00:00.000000000 Z
|
|
11
12
|
dependencies: []
|
|
13
|
+
description:
|
|
12
14
|
email: robinvdvleuten@gmail.com
|
|
13
15
|
executables: []
|
|
14
16
|
extensions: []
|
|
@@ -20,12 +22,14 @@ files:
|
|
|
20
22
|
- data/address_formats.dump
|
|
21
23
|
- data/address_formats.json
|
|
22
24
|
- data/country/af.json
|
|
25
|
+
- data/country/ak.json
|
|
23
26
|
- data/country/am.json
|
|
24
27
|
- data/country/ar-LY.json
|
|
25
28
|
- data/country/ar-SA.json
|
|
26
29
|
- data/country/ar.json
|
|
27
30
|
- data/country/as.json
|
|
28
31
|
- data/country/az.json
|
|
32
|
+
- data/country/ba.json
|
|
29
33
|
- data/country/be.json
|
|
30
34
|
- data/country/bg.json
|
|
31
35
|
- data/country/bn-IN.json
|
|
@@ -34,6 +38,7 @@ files:
|
|
|
34
38
|
- data/country/ca.json
|
|
35
39
|
- data/country/chr.json
|
|
36
40
|
- data/country/cs.json
|
|
41
|
+
- data/country/cv.json
|
|
37
42
|
- data/country/cy.json
|
|
38
43
|
- data/country/da.json
|
|
39
44
|
- data/country/de-AT.json
|
|
@@ -45,8 +50,11 @@ files:
|
|
|
45
50
|
- data/country/en-001.json
|
|
46
51
|
- data/country/en-AU.json
|
|
47
52
|
- data/country/en-CA.json
|
|
48
|
-
- data/country/en-
|
|
49
|
-
- data/country/en-
|
|
53
|
+
- data/country/en-EE.json
|
|
54
|
+
- data/country/en-GE.json
|
|
55
|
+
- data/country/en-LT.json
|
|
56
|
+
- data/country/en-LV.json
|
|
57
|
+
- data/country/en-UA.json
|
|
50
58
|
- data/country/en.json
|
|
51
59
|
- data/country/es-419.json
|
|
52
60
|
- data/country/es-AR.json
|
|
@@ -94,6 +102,7 @@ files:
|
|
|
94
102
|
- data/country/it.json
|
|
95
103
|
- data/country/ja.json
|
|
96
104
|
- data/country/ka.json
|
|
105
|
+
- data/country/kk-Arab.json
|
|
97
106
|
- data/country/kk.json
|
|
98
107
|
- data/country/km.json
|
|
99
108
|
- data/country/ko-KP.json
|
|
@@ -120,10 +129,13 @@ files:
|
|
|
120
129
|
- data/country/ps.json
|
|
121
130
|
- data/country/pt-PT.json
|
|
122
131
|
- data/country/pt.json
|
|
132
|
+
- data/country/qu.json
|
|
133
|
+
- data/country/rm.json
|
|
123
134
|
- data/country/ro-MD.json
|
|
124
135
|
- data/country/ro.json
|
|
125
136
|
- data/country/ru-UA.json
|
|
126
137
|
- data/country/ru.json
|
|
138
|
+
- data/country/shn.json
|
|
127
139
|
- data/country/si.json
|
|
128
140
|
- data/country/sk.json
|
|
129
141
|
- data/country/sl.json
|
|
@@ -605,6 +617,8 @@ files:
|
|
|
605
617
|
- data/subdivision/EG.json
|
|
606
618
|
- data/subdivision/ES.json
|
|
607
619
|
- data/subdivision/FM.json
|
|
620
|
+
- data/subdivision/GB.json
|
|
621
|
+
- data/subdivision/GT.json
|
|
608
622
|
- data/subdivision/HK-2705954f46a43ef0ad522412afe6ed6ee8196fe4.json
|
|
609
623
|
- data/subdivision/HK-29ceaf41d01206ba481b188116cbb302b82663cf.json
|
|
610
624
|
- data/subdivision/HK-ff51a84233701e6a1d18f70acf4b3f909e4c6a09.json
|
|
@@ -726,6 +740,7 @@ licenses:
|
|
|
726
740
|
metadata:
|
|
727
741
|
bug_tracker_uri: https://github.com/robinvdvleuten/addressing/issues
|
|
728
742
|
changelog_uri: https://github.com/robinvdvleuten/addressing/blob/main/CHANGELOG.md
|
|
743
|
+
post_install_message:
|
|
729
744
|
rdoc_options: []
|
|
730
745
|
require_paths:
|
|
731
746
|
- lib
|
|
@@ -733,14 +748,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
733
748
|
requirements:
|
|
734
749
|
- - ">="
|
|
735
750
|
- !ruby/object:Gem::Version
|
|
736
|
-
version: '3.
|
|
751
|
+
version: '3.3'
|
|
737
752
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
738
753
|
requirements:
|
|
739
754
|
- - ">="
|
|
740
755
|
- !ruby/object:Gem::Version
|
|
741
756
|
version: '0'
|
|
742
757
|
requirements: []
|
|
743
|
-
rubygems_version: 3.
|
|
758
|
+
rubygems_version: 3.5.22
|
|
759
|
+
signing_key:
|
|
744
760
|
specification_version: 4
|
|
745
761
|
summary: Addressing library powered by CLDR and Google's address data
|
|
746
762
|
test_files: []
|
|
File without changes
|
|
File without changes
|