address_composer 0.1.2.pre → 1.0.0

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 +7 -3
  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 +166 -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 +1324 -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 +69 -2
  50. data/address-formatting/testcases/other/xx.yaml +28 -0
  51. data/address_composer.gemspec +4 -4
  52. data/lib/address_composer.rb +10 -9
  53. data/lib/address_composer/version.rb +1 -1
  54. metadata +24 -19
  55. data/.ruby-version +0 -1
@@ -7,6 +7,7 @@ components:
7
7
  country_code: hm
8
8
  island: Heard Island
9
9
  expected: |
10
+ Heard Island
10
11
  Heard Island and McDonald Islands
11
12
  Australia
12
13
 
@@ -28,7 +28,6 @@ components:
28
28
  expected: |
29
29
  Kilkenny
30
30
  Ireland
31
-
32
31
  ---
33
32
  # Friar's Hill - 52.54593995, -6.95706874120767
34
33
  description: Friar's Hill, Graiguenamanagh
@@ -44,7 +43,28 @@ expected: |
44
43
  Graiguenamanagh
45
44
  County Kilkenny
46
45
  Ireland
47
-
46
+ ---
47
+ # 53.3388,-6.2691
48
+ description: condense "Dublin, County Dublin"
49
+ components:
50
+ city: Dublin
51
+ city_district: Wood Quay A ED
52
+ continent: Europe
53
+ country: Ireland
54
+ country_code: ie
55
+ county: County Dublin
56
+ county_code: D
57
+ library: The National Archives
58
+ postcode: D02 TD99
59
+ road: Bishop Street
60
+ state: Leinster
61
+ state_code: L
62
+ expected: |
63
+ The National Archives
64
+ Bishop Street
65
+ Wood Quay A ED
66
+ Dublin
67
+ Ireland
48
68
  ---
49
69
  # 52.6726,-8.6407
50
70
  description: remove "The Metropolitan District of"
@@ -63,5 +83,27 @@ expected: |
63
83
  Shelbourne Road
64
84
  Farranshone
65
85
  Limerick
66
- County Limerick
67
86
  Ireland
87
+ ---
88
+ # 53.49137,-10.02117
89
+ description: no "Electoral Division"
90
+ components:
91
+ city_district: Clifden Electoral Division
92
+ continent: Europe
93
+ country: Ireland
94
+ country_code: ie
95
+ county: County Galway
96
+ county_code: G
97
+ guest_house: Connemara Country Lodge
98
+ region: Conamara Municipal District
99
+ road: N59
100
+ state: Connacht
101
+ state_code: C
102
+ town: Clifden
103
+ expected: |
104
+ Connemara Country Lodge
105
+ N59
106
+ Clifden
107
+ County Galway
108
+ Ireland
109
+
@@ -13,7 +13,8 @@ components:
13
13
  expected: |
14
14
  3FM
15
15
  45 Victoria Street
16
- Douglas IM1 2AY
16
+ Douglas
17
+ IM1 2AY
17
18
  Isle of Man
18
19
 
19
20
 
@@ -11,5 +11,6 @@ components:
11
11
  town: Saint Helier
12
12
  expected: |
13
13
  5 Le Geyt Street
14
- Saint Helier JE2 4TN
14
+ Saint Helier
15
+ JE2 4TN
15
16
  Jersey, Channel Islands
@@ -16,3 +16,20 @@ expected: |
16
16
  Åkebergveien 28
17
17
  0650 Oslo
18
18
  Norway
19
+ ---
20
+ description: house in village with postal_city
21
+ components:
22
+ country: Norge
23
+ country_code: "no"
24
+ county: Viken
25
+ house_number: 33
26
+ neighbourhood: Belset
27
+ postal_city: Rykkinn
28
+ postcode: 1349
29
+ road: Grindstuveien
30
+ suburb: Angerst
31
+ village: Ringvoll
32
+ expected: |
33
+ Grindstuveien 33
34
+ 1349 Rykkinn
35
+ Norge
@@ -14,3 +14,25 @@ expected: |
14
14
  Avenida Conselheiro Barjona de Freitas 11
15
15
  1500-203 Lisbon
16
16
  Portugal
17
+ ---
18
+ # Guest house in the Azores
19
+ description: 37.74851,-25.60450
20
+ components:
21
+ archipelago: Azores
22
+ city: Ponta Delgada
23
+ city_district: Rosto do Cão (Livramento)
24
+ country: Portugal
25
+ country_code: pt
26
+ guest_house: Casa Do Populo
27
+ house_number: 1015
28
+ neighbourhood: Livramento
29
+ postcode: 9500-614
30
+ road: Rua Padre Domingos da Silva Costay
31
+ state_district: São Miguel
32
+ expected: |
33
+ Casa Do Populo
34
+ Rua Padre Domingos da Silva Costay 1015
35
+ 9500-614 Ponta Delgada
36
+ Azores
37
+ Portugal
38
+
@@ -20,3 +20,33 @@ expected: |
20
20
  Санкт-Петербург
21
21
  Российская Федерация
22
22
  190000
23
+ ---
24
+ description: village 55.8931701, 63.7019487
25
+ components:
26
+ city : Батуринский сельсовет
27
+ country : Россия
28
+ country_code : ru
29
+ county : Шадринский район
30
+ hamlet : Камчатка
31
+ state : Курганская область
32
+ expected: |
33
+ Камчатка
34
+ Батуринский сельсовет
35
+ Шадринский район
36
+ Россия
37
+ ---
38
+ # island
39
+ description: use island name
40
+ components:
41
+ city : Малиновараккское сельское поселение
42
+ country : Россия
43
+ country_code : ru
44
+ county : Лоухский район
45
+ island : Ярославль
46
+ state : Республика Карелия
47
+ expected: |
48
+ Ярославль
49
+ Малиновараккское сельское поселение
50
+ Лоухский район
51
+ Россия
52
+
@@ -1,5 +1,5 @@
1
1
  ---
2
- description: Chinatown Singapore
2
+ description: SG no postcode
3
3
  components:
4
4
  country: Singapore
5
5
  country_code: SG
@@ -24,3 +24,20 @@ expected: |
24
24
  16 Sandilands Road
25
25
  Singapore 546080
26
26
  Singapore
27
+ ---
28
+ description: no city, 1.30585,103.78158
29
+ components:
30
+ country: Singapore
31
+ country_code: sg
32
+ county: Southwest
33
+ house_number: 26
34
+ postcode: 130026
35
+ residential: Dover Gardens
36
+ road: Dover Crescent
37
+ suburb: Queenstown
38
+ expected: |
39
+ 26 Dover Crescent, Dover Gardens
40
+ Singapore 130026
41
+ Singapore
42
+
43
+
@@ -26,7 +26,8 @@ components:
26
26
  state: Tristan da Cunha
27
27
  expected: |
28
28
  Prince Philip Hall
29
- Edinburgh of the Seven Seas TDCU 1ZZ
29
+ Edinburgh of the Seven Seas
30
+ TDCU 1ZZ
30
31
  Tristan da Cunha
31
32
  United Kingdom
32
33
 
@@ -18,6 +18,19 @@ expected: |
18
18
  6/6A Kampala Road
19
19
  Kampala
20
20
  Uganda
21
+ ---
22
+ description: subcounty
23
+ components:
24
+ country: Uganda
25
+ country_code: ug
26
+ state: Arua
27
+ subcounty: Ayivuni
28
+ expected: |
29
+ Ayivuni
30
+ Arua
31
+ Uganda
32
+
33
+
21
34
 
22
35
 
23
36
 
@@ -6,7 +6,7 @@ components:
6
6
  country_code: um
7
7
  island: Wake Island
8
8
  expected: |
9
- Wake Island, UM
9
+ Wake Island, US Minor Outlying Islands
10
10
  United States of America
11
11
 
12
12
 
@@ -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
@@ -183,3 +183,70 @@ expected: |
183
183
  Dronningens Gade
184
184
  Charlotte Amalie, VI 00803
185
185
  United States of America
186
+ #
187
+ # state_district
188
+ ---
189
+ description: state_district
190
+ components:
191
+ country: United States of America
192
+ country_code: us
193
+ state: New York
194
+ state_district: New York
195
+ expected: |
196
+ New York, New York
197
+ United States of America
198
+ ---
199
+ description: just state
200
+ components:
201
+ country: United States of America
202
+ country_code: us
203
+ state: New York
204
+ expected: |
205
+ New York
206
+ United States of America
207
+ #
208
+ # municipality
209
+ ---
210
+ description: municipality
211
+ components:
212
+ country: United States of America
213
+ country_code: us
214
+ county: Saginaw County
215
+ municipality: Taymouth Township
216
+ state: Michigan
217
+ village: Burt
218
+ expected: |
219
+ Burt
220
+ Taymouth Township, Michigan
221
+ United States of America
222
+ #
223
+ # village
224
+ ---
225
+ description: village
226
+ components:
227
+ country: United States of America
228
+ country_code: us
229
+ county: Costilla County
230
+ postcode: "08113"
231
+ state: Colorado
232
+ village: Fort Garland
233
+ expected: |
234
+ Fort Garland
235
+ Costilla County, CO 08113
236
+ United States of America
237
+ #
238
+ # hamlet
239
+ ---
240
+ description: hamlet
241
+ components:
242
+ city: Homestead
243
+ country: United States of America
244
+ country_code: us
245
+ county: Miami-Dade County
246
+ hamlet: Homestead Trailer Park
247
+ postcode: 33030
248
+ state: Florida
249
+ expected: |
250
+ Homestead Trailer Park
251
+ Homestead, FL 33030
252
+ 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,13 +1,14 @@
1
1
  require "address_composer/version"
2
- require "YAML"
2
+ require "yaml"
3
3
  require "mustache"
4
4
 
5
5
  class AddressComposer
6
- Templates = YAML.load_file(File.join("address-formatting/conf/countries/worldwide.yaml"))
7
- ComponentsList = Psych.load_stream(File.read("address-formatting/conf/components.yaml"))
6
+ GEM_ROOT = Gem::Specification.find_by_name("address_composer").gem_dir
7
+ Templates = YAML.load_file(File.join(GEM_ROOT, "address-formatting", "conf", "countries", "worldwide.yaml"))
8
+ ComponentsList = Psych.load_stream(File.read(File.join(GEM_ROOT,"address-formatting", "conf","components.yaml")))
8
9
  AllComponents = ComponentsList.map { |h| h["name"] } + ComponentsList.flat_map { |h| h["aliases"] }.compact
9
- StateCodes = YAML.load_file(File.join("address-formatting/conf/state_codes.yaml"))
10
- CountyCodes = YAML.load_file(File.open("address-formatting/conf/county_codes.yaml"))
10
+ StateCodes = YAML.load_file(File.join(GEM_ROOT, "address-formatting", "conf", "state_codes.yaml"))
11
+ CountyCodes = YAML.load_file(File.join(GEM_ROOT, "address-formatting", "conf", "county_codes.yaml"))
11
12
 
12
13
  class Template < Mustache
13
14
  def first
@@ -24,12 +25,12 @@ class AddressComposer
24
25
  attr_accessor :components
25
26
 
26
27
  def initialize(components)
27
- self.components = components
28
- end
28
+ self.components = components.dup
29
29
 
30
- def compose
31
30
  normalize_components
31
+ end
32
32
 
33
+ def compose
33
34
  if components["country_code"]
34
35
  result = Template.render(template, components).squeeze("\n").lstrip.gsub(/\s*\n\s*/, "\n")
35
36
  result = post_format_replace(result)
@@ -154,7 +155,7 @@ class AddressComposer
154
155
  unknown_components = components.keys - AllComponents
155
156
 
156
157
  components["attention"] = unknown_components.map do |unknown|
157
- components[unknown]
158
+ components.delete(unknown)
158
159
  end.join(" ")
159
160
  end
160
161
 
@@ -1,3 +1,3 @@
1
1
  class AddressComposer
2
- VERSION = "0.1.2.pre".freeze
2
+ VERSION = "1.0.0".freeze
3
3
  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.2.pre
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alejandro Arrufat
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-05 00:00:00.000000000 Z
11
+ date: 2021-08-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
@@ -407,7 +413,7 @@ metadata:
407
413
  documentation_uri: https://github.com/mirubiri/address_composer/README.md
408
414
  homepage_uri: https://github.com/mirubiri/address_composer
409
415
  source_code_uri: https://github.com/mirubiri/address_composer
410
- post_install_message:
416
+ post_install_message:
411
417
  rdoc_options: []
412
418
  require_paths:
413
419
  - lib
@@ -418,13 +424,12 @@ 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
427
- signing_key:
431
+ rubygems_version: 3.2.22
432
+ signing_key:
428
433
  specification_version: 4
429
434
  summary: Universal international address composer in Ruby
430
435
  test_files: []