address_composer 0.1.3.pre → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/main.yml +25 -0
  3. data/.gitignore +2 -0
  4. data/.gitmodules +1 -1
  5. data/Gemfile.lock +24 -23
  6. data/README.md +3 -1
  7. data/address-formatting/.travis.yml +8 -6
  8. data/address-formatting/README.md +9 -2
  9. data/address-formatting/SECURITY.md +5 -0
  10. data/address-formatting/conf/abbreviations/{dk.yaml → da.yaml} +0 -3
  11. data/address-formatting/conf/abbreviations/de.yaml +0 -2
  12. data/address-formatting/conf/abbreviations/en.yaml +1 -1
  13. data/address-formatting/conf/abbreviations/fr.yaml +1 -1
  14. data/address-formatting/conf/abbreviations/hu.yaml +1 -2
  15. data/address-formatting/conf/abbreviations/nl.yaml +14 -1
  16. data/address-formatting/conf/abbreviations/no.yaml +16 -0
  17. data/address-formatting/conf/abbreviations/pl.yaml +24 -0
  18. data/address-formatting/conf/abbreviations/pt.yaml +0 -1
  19. data/address-formatting/conf/abbreviations/ru.yaml +45 -0
  20. data/address-formatting/conf/abbreviations/uk.yaml +0 -3
  21. data/address-formatting/conf/abbreviations/vn.yaml +7 -0
  22. data/address-formatting/conf/components.yaml +23 -4
  23. data/address-formatting/conf/countries/worldwide.yaml +168 -122
  24. data/address-formatting/conf/country2lang.yaml +3 -3
  25. data/address-formatting/conf/county_codes.yaml +369 -15
  26. data/address-formatting/conf/state_codes.yaml +1435 -129
  27. data/address-formatting/testcases/countries/as.yaml +7 -8
  28. data/address-formatting/testcases/countries/be.yaml +35 -0
  29. data/address-formatting/testcases/countries/bf.yaml +15 -1
  30. data/address-formatting/testcases/countries/ca.yaml +29 -5
  31. data/address-formatting/testcases/countries/cn.yaml +9 -0
  32. data/address-formatting/testcases/countries/de.yaml +1 -1
  33. data/address-formatting/testcases/countries/fr.yaml +81 -1
  34. data/address-formatting/testcases/countries/gb.yaml +90 -8
  35. data/address-formatting/testcases/countries/gg.yaml +2 -1
  36. data/address-formatting/testcases/countries/gu.yaml +2 -2
  37. data/address-formatting/testcases/countries/hk.yaml +18 -8
  38. data/address-formatting/testcases/countries/hm.yaml +1 -0
  39. data/address-formatting/testcases/countries/ie.yaml +45 -3
  40. data/address-formatting/testcases/countries/im.yaml +2 -1
  41. data/address-formatting/testcases/countries/je.yaml +2 -1
  42. data/address-formatting/testcases/countries/no.yaml +17 -0
  43. data/address-formatting/testcases/countries/pt.yaml +22 -0
  44. data/address-formatting/testcases/countries/ru.yaml +30 -0
  45. data/address-formatting/testcases/countries/sg.yaml +18 -1
  46. data/address-formatting/testcases/countries/sh.yaml +2 -1
  47. data/address-formatting/testcases/countries/ug.yaml +13 -0
  48. data/address-formatting/testcases/countries/um.yaml +1 -1
  49. data/address-formatting/testcases/countries/us.yaml +95 -10
  50. data/address-formatting/testcases/other/xx.yaml +28 -0
  51. data/address_composer.gemspec +4 -4
  52. data/lib/address_composer/version.rb +1 -1
  53. data/lib/address_composer.rb +9 -9
  54. metadata +21 -16
  55. data/.ruby-version +0 -1
@@ -75,7 +75,7 @@ components:
75
75
  county: Santa Clara County
76
76
  state: California
77
77
  expected: |
78
- Palo Alto, CA
78
+ Palo Alto, California
79
79
  United States of America
80
80
  ---
81
81
  description: NY, NY
@@ -85,7 +85,7 @@ components:
85
85
  country_code: US
86
86
  state: New York
87
87
  expected: |
88
- New York, NY
88
+ New York, New York
89
89
  United States of America
90
90
  ---
91
91
  description: house number in New York, no city
@@ -139,6 +139,24 @@ expected: |
139
139
  928 Flagler Avenue
140
140
  Edgewater, FL 32132
141
141
  United States of America
142
+
143
+ ---
144
+ description: clean up "Town of " 40.7805,-73.4875
145
+ components:
146
+ country: United States
147
+ country_code: us
148
+ county: Nassau County
149
+ house_number: 4
150
+ municipality: Town of Oyster Bay
151
+ postcode: 11803
152
+ road: Lakeville Lane
153
+ state: New York
154
+ state_code: NY
155
+ expected: |
156
+ 4 Lakeville Lane
157
+ Oyster Bay, NY 11803
158
+ United States of America
159
+
142
160
  ---
143
161
  description: use county if no city
144
162
  components:
@@ -170,16 +188,83 @@ expected: |
170
188
  ---
171
189
  description: Library in Charlotte Amalie, 18.34119,-64.93546
172
190
  components:
173
- country: United States of America
174
- country_code: us
175
- county: St. Thomas Island
176
- library: Enid M Baa Library and Archives
177
- postcode: "00803"
178
- road: Dronningens Gade
179
- state: United States Virgin Islands
180
- town: Charlotte Amalie
191
+ country: United States of America
192
+ country_code: us
193
+ county: St. Thomas Island
194
+ library: Enid M Baa Library and Archives
195
+ postcode: "00803"
196
+ road: Dronningens Gade
197
+ state: United States Virgin Islands
198
+ town: Charlotte Amalie
181
199
  expected: |
182
200
  Enid M Baa Library and Archives
183
201
  Dronningens Gade
184
202
  Charlotte Amalie, VI 00803
185
203
  United States of America
204
+ #
205
+ # state_district
206
+ ---
207
+ description: state_district
208
+ components:
209
+ country: United States of America
210
+ country_code: us
211
+ state: New York
212
+ state_district: New York
213
+ expected: |
214
+ New York, New York
215
+ United States of America
216
+ ---
217
+ description: just state
218
+ components:
219
+ country: United States of America
220
+ country_code: us
221
+ state: New York
222
+ expected: |
223
+ New York
224
+ United States of America
225
+ #
226
+ # municipality
227
+ ---
228
+ description: municipality
229
+ components:
230
+ country: United States of America
231
+ country_code: us
232
+ county: Saginaw County
233
+ municipality: Taymouth Township
234
+ state: Michigan
235
+ village: Burt
236
+ expected: |
237
+ Burt
238
+ Taymouth Township, Michigan
239
+ United States of America
240
+ #
241
+ # village
242
+ ---
243
+ description: village
244
+ components:
245
+ country: United States of America
246
+ country_code: us
247
+ county: Costilla County
248
+ postcode: "08113"
249
+ state: Colorado
250
+ village: Fort Garland
251
+ expected: |
252
+ Fort Garland
253
+ Costilla County, CO 08113
254
+ United States of America
255
+ #
256
+ # hamlet
257
+ ---
258
+ description: hamlet
259
+ components:
260
+ city: Homestead
261
+ country: United States of America
262
+ country_code: us
263
+ county: Miami-Dade County
264
+ hamlet: Homestead Trailer Park
265
+ postcode: 33030
266
+ state: Florida
267
+ expected: |
268
+ Homestead Trailer Park
269
+ Homestead, FL 33030
270
+ United States of America
@@ -0,0 +1,28 @@
1
+ # Dummy test country to check that we fall back to the defaults
2
+ ---
3
+ description: generic format
4
+ components:
5
+ city: City
6
+ country: Null Island
7
+ country_code: XX
8
+ county: County
9
+ house_number: 123
10
+ postcode: PCPCPC
11
+ road: Main Street
12
+ state: State
13
+ suburb: The Hood
14
+ expected: |
15
+ Main Street 123
16
+ PCPCPC City
17
+ Null Island
18
+ ---
19
+ description: generic fallback
20
+ components:
21
+ city: City
22
+ country: Null Island
23
+ country_code: XX
24
+ state: State
25
+ expected: |
26
+ City
27
+ State
28
+ Null Island
@@ -28,9 +28,9 @@ Gem::Specification.new do |gem|
28
28
 
29
29
  gem.add_runtime_dependency "mustache", "~> 1.1"
30
30
 
31
- gem.add_development_dependency "bundler", "~> 1.17"
32
- gem.add_development_dependency "pry", "~> 0.13"
33
- gem.add_development_dependency "pry-byebug", "~> 3.9"
31
+ gem.add_development_dependency "bundler", "~> 2.2"
32
+ gem.add_development_dependency "pry", "~> 0.14"
33
+ gem.add_development_dependency "pry-byebug", "~> 3.8"
34
34
  gem.add_development_dependency "rake", "~> 13.0"
35
- gem.add_development_dependency "rspec", "~> 3.0"
35
+ gem.add_development_dependency "rspec", "~> 3.10"
36
36
  end
@@ -1,3 +1,3 @@
1
1
  class AddressComposer
2
- VERSION = "0.1.3.pre".freeze
2
+ VERSION = "1.0.1".freeze
3
3
  end
@@ -1,5 +1,5 @@
1
1
  require "address_composer/version"
2
- require "YAML"
2
+ require "yaml"
3
3
  require "mustache"
4
4
 
5
5
  class AddressComposer
@@ -25,12 +25,12 @@ class AddressComposer
25
25
  attr_accessor :components
26
26
 
27
27
  def initialize(components)
28
- self.components = components
29
- end
28
+ self.components = components.dup
30
29
 
31
- def compose
32
30
  normalize_components
31
+ end
33
32
 
33
+ def compose
34
34
  if components["country_code"]
35
35
  result = Template.render(template, components).squeeze("\n").lstrip.gsub(/\s*\n\s*/, "\n")
36
36
  result = post_format_replace(result)
@@ -155,7 +155,7 @@ class AddressComposer
155
155
  unknown_components = components.keys - AllComponents
156
156
 
157
157
  components["attention"] = unknown_components.map do |unknown|
158
- components[unknown]
158
+ components.delete(unknown)
159
159
  end.join(" ")
160
160
  end
161
161
 
@@ -178,14 +178,14 @@ class AddressComposer
178
178
  components["postcode"] = components["postcode"].split(",").first
179
179
  end
180
180
 
181
- # Clean values with "", nil or []
182
- self.components = components.reject { |_, v| v.nil? || v.empty? }
183
-
184
181
  # If country is a number use the state as country
185
- if components["country"]&.match?(/[0-9]/)
182
+ if components["state"] && components["country"]&.match?(/^\d+$/)
186
183
  components["country"] = components["state"]
187
184
  end
188
185
 
186
+ # Clean values with "", nil or []
187
+ self.components = components.reject { |_, v| v.nil? || v.empty? }
188
+
189
189
  # Remove components with URL
190
190
  components.delete_if { |_, v| v.match?(URI::DEFAULT_PARSER.make_regexp) }
191
191
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: address_composer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3.pre
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alejandro Arrufat
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-18 00:00:00.000000000 Z
11
+ date: 2021-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mustache
@@ -30,42 +30,42 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.17'
33
+ version: '2.2'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.17'
40
+ version: '2.2'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: pry
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.13'
47
+ version: '0.14'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0.13'
54
+ version: '0.14'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: pry-byebug
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '3.9'
61
+ version: '3.8'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '3.9'
68
+ version: '3.8'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '3.0'
89
+ version: '3.10'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '3.0'
96
+ version: '3.10'
97
97
  description: Address Composer formats address components using worldwide regions formatting
98
98
  templates
99
99
  email:
@@ -102,11 +102,11 @@ executables: []
102
102
  extensions: []
103
103
  extra_rdoc_files: []
104
104
  files:
105
+ - ".github/workflows/main.yml"
105
106
  - ".gitignore"
106
107
  - ".gitmodules"
107
108
  - ".rspec"
108
109
  - ".rubocop.yml"
109
- - ".ruby-version"
110
110
  - ".travis.yml"
111
111
  - Gemfile
112
112
  - Gemfile.lock
@@ -116,12 +116,13 @@ files:
116
116
  - address-formatting/.travis.yml
117
117
  - address-formatting/LICENSE.txt
118
118
  - address-formatting/README.md
119
+ - address-formatting/SECURITY.md
119
120
  - address-formatting/bin/coverage.pl
120
121
  - address-formatting/bin/run_tests.t
121
122
  - address-formatting/conf/abbreviations/ca.yaml
122
123
  - address-formatting/conf/abbreviations/cs.yaml
124
+ - address-formatting/conf/abbreviations/da.yaml
123
125
  - address-formatting/conf/abbreviations/de.yaml
124
- - address-formatting/conf/abbreviations/dk.yaml
125
126
  - address-formatting/conf/abbreviations/en.yaml
126
127
  - address-formatting/conf/abbreviations/es.yaml
127
128
  - address-formatting/conf/abbreviations/et.yaml
@@ -131,12 +132,16 @@ files:
131
132
  - address-formatting/conf/abbreviations/hu.yaml
132
133
  - address-formatting/conf/abbreviations/it.yaml
133
134
  - address-formatting/conf/abbreviations/nl.yaml
135
+ - address-formatting/conf/abbreviations/no.yaml
136
+ - address-formatting/conf/abbreviations/pl.yaml
134
137
  - address-formatting/conf/abbreviations/pt.yaml
135
138
  - address-formatting/conf/abbreviations/ro.yaml
139
+ - address-formatting/conf/abbreviations/ru.yaml
136
140
  - address-formatting/conf/abbreviations/se.yaml
137
141
  - address-formatting/conf/abbreviations/sk.yaml
138
142
  - address-formatting/conf/abbreviations/tr.yaml
139
143
  - address-formatting/conf/abbreviations/uk.yaml
144
+ - address-formatting/conf/abbreviations/vn.yaml
140
145
  - address-formatting/conf/components.yaml
141
146
  - address-formatting/conf/countries/worldwide.yaml
142
147
  - address-formatting/conf/country2lang.yaml
@@ -394,6 +399,7 @@ files:
394
399
  - address-formatting/testcases/countries/zm.yaml
395
400
  - address-formatting/testcases/countries/zw.yaml
396
401
  - address-formatting/testcases/other/null.yaml
402
+ - address-formatting/testcases/other/xx.yaml
397
403
  - address_composer.gemspec
398
404
  - bin/console
399
405
  - bin/setup
@@ -418,12 +424,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
418
424
  version: '2.4'
419
425
  required_rubygems_version: !ruby/object:Gem::Requirement
420
426
  requirements:
421
- - - ">"
427
+ - - ">="
422
428
  - !ruby/object:Gem::Version
423
- version: 1.3.1
429
+ version: '0'
424
430
  requirements: []
425
- rubyforge_project:
426
- rubygems_version: 2.6.14.3
431
+ rubygems_version: 3.2.22
427
432
  signing_key:
428
433
  specification_version: 4
429
434
  summary: Universal international address composer in Ruby
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 2.4.5