worldly 0.1.8 → 1.0.3
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 +5 -5
- data/CHANGELOG.md +12 -0
- data/README.md +11 -2
- data/lib/data/countries.yml +19 -40
- data/lib/worldly/country.rb +25 -2
- data/lib/worldly/version.rb +1 -1
- data/worldly.gemspec +2 -2
- metadata +11 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b0c64f1e5bac5a7a89daa04c4b85268c3061235c001cb1c1e6264bc6c4dfc681
|
4
|
+
data.tar.gz: 11df37ac6026dd7ae33b38afa8022536f6f05fc510789d416c54adafb13a0383
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55a8dd109241ca226cb61dc56f1b4e82066939abb14f63f5692abb47ca6031f9a35f067cb3105b247ecc31ef8007873b58c9f4dded49b257f3a8752dcc5219d7
|
7
|
+
data.tar.gz: 89deda2187e34cdc143617312a05c5e57eb9d058fd9215fc679f170eaa3bfc6a3e330ff861dbd0716a7210e578b0fef7919ba482657774af37e3fd00f87d30e4
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
|
+
= Version 1.0.2 - 2017-11-08
|
2
|
+
* Fix: NZ suburb optional.
|
3
|
+
= Version 1.0.1 - 2017-04-05
|
4
|
+
* Fix: Samoa address format fixed by removing region.
|
5
|
+
= Version 1.0.0 - 2017-04-05
|
6
|
+
* Change: Removed Locality
|
7
|
+
* Change: Updated some country formats
|
8
|
+
|
9
|
+
= Version 0.1.9 - 2016-07-26
|
10
|
+
* Improvement: Added to_display method
|
11
|
+
|
1
12
|
= Version 0.1.8 - 2016-01-20
|
2
13
|
* Improvement: Address line 3 not accepted
|
14
|
+
|
3
15
|
= Version 0.1.7 - 2015-04-09
|
4
16
|
* Fix: format_values method - dup value to ensure original data not changed
|
5
17
|
|
data/README.md
CHANGED
@@ -52,7 +52,7 @@ Retrieve a country using it's country code
|
|
52
52
|
country.alpha3 => AUS
|
53
53
|
country.country_code => 61
|
54
54
|
```
|
55
|
-
Worldly uses the address fields
|
55
|
+
Worldly uses the address fields city, region & postcode. Address1, Address2 and Country are implied and hence not added. A call to country.fields will return the fields not implied that the country address uses.
|
56
56
|
```
|
57
57
|
country.fields => {:city=>{:label=>"City", :format=>["upcase"], :required=>true}, :region=>{:label=>"State", :format=>["upcase"], :required=>true}, :postcode=>{:label=>"Post Code", :required=>true}}
|
58
58
|
```
|
@@ -67,7 +67,6 @@ Each field notes the following details:
|
|
67
67
|
Field Methods
|
68
68
|
```
|
69
69
|
country.has_field?(:city) => true
|
70
|
-
country.has_field?(:locality) => false
|
71
70
|
country.required_fields => {:city=>{:label=>"City", :format=>["upcase"], :required=>true}, :region=>{:label=>"State", :format=>["upcase"], :required=>true}, :postcode=>{:label=>"Post Code", :required=>true}}
|
72
71
|
```
|
73
72
|
To retrieve all fields including address1, address2 & country use
|
@@ -108,6 +107,16 @@ To have the address formatted correctly for mailing use to_print(attributes, sen
|
|
108
107
|
country.to_print({address1: '12 hey St', region:'NSW', postcode: '2000' }, 'AU')
|
109
108
|
=> "12 hey St\nNSW 2000"
|
110
109
|
```
|
110
|
+
|
111
|
+
There is also a to_display method which ignores certain address formatting rules:
|
112
|
+
|
113
|
+
```
|
114
|
+
country.to_print({address1: '12 hey St', address2: '', postcode: '2000', city: 'Newtown', state:'NSW'})
|
115
|
+
=> "12 hey St\nNEWTOWN 2000\nAustralia"
|
116
|
+
country.to_display({address1: '12 hey St', address2: '', postcode: '2000', city: 'Newtown', state:'NSW'})
|
117
|
+
=> "12 hey St\nNewtown 2000\nAustralia"
|
118
|
+
```
|
119
|
+
|
111
120
|
## Contributing
|
112
121
|
|
113
122
|
If you find a country with mission regions, or a country missing address formatting information you can create a issue ticket with corrections.
|
data/lib/data/countries.yml
CHANGED
@@ -8,7 +8,7 @@ AD:
|
|
8
8
|
city:
|
9
9
|
label: City
|
10
10
|
postcode:
|
11
|
-
label: '
|
11
|
+
label: 'Postcode'
|
12
12
|
address_format: "{{address1}}\n{{address2}}\n{{address3}}\n{{postcode}} {{city}}\n{{country}}"
|
13
13
|
AE:
|
14
14
|
name: United Arab Emirates
|
@@ -82,8 +82,8 @@ AR:
|
|
82
82
|
postcode:
|
83
83
|
label: 'Post Code'
|
84
84
|
region:
|
85
|
-
label:
|
86
|
-
address_format: "{{address1}}\n{{address2}}\n{{address3}}\n{{postcode}} {{city}}\n{{country}}"
|
85
|
+
label: State
|
86
|
+
address_format: "{{address1}}\n{{address2}}\n{{address3}}\n{{postcode}} {{city}}\n{{state}}\n{{country}}"
|
87
87
|
AS:
|
88
88
|
name: American Samoa
|
89
89
|
alpha2: AS
|
@@ -218,15 +218,13 @@ BR:
|
|
218
218
|
alpha3: BRA
|
219
219
|
country_code: '55'
|
220
220
|
fields:
|
221
|
-
locality:
|
222
|
-
name: Suburb
|
223
221
|
city:
|
224
222
|
label: City
|
225
223
|
region:
|
226
224
|
label: State
|
227
225
|
postcode:
|
228
226
|
label: 'Post Code'
|
229
|
-
address_format: "{{address1}}\n{{address2}}\n{{address3}}\n{{
|
227
|
+
address_format: "{{address1}}\n{{address2}}\n{{address3}}\n{{city}} {{region}}\n{{postcode}}\n{{country}}"
|
230
228
|
BS:
|
231
229
|
name: Bahamas
|
232
230
|
alpha2: BS
|
@@ -339,9 +337,6 @@ CN:
|
|
339
337
|
alpha3: CHN
|
340
338
|
country_code: '86'
|
341
339
|
fields:
|
342
|
-
locality:
|
343
|
-
label: Suburb
|
344
|
-
required: false
|
345
340
|
city:
|
346
341
|
label: City
|
347
342
|
required: false
|
@@ -351,7 +346,7 @@ CN:
|
|
351
346
|
- upcase
|
352
347
|
region:
|
353
348
|
label: Province
|
354
|
-
address_format: "{{address1}}\n{{address2}}\n{{address3}}\n{{
|
349
|
+
address_format: "{{address1}}\n{{address2}}\n{{address3}}\n{{city}}\n{{postcode}} {{region}}\n{{country}}"
|
355
350
|
CO:
|
356
351
|
name: Colombia
|
357
352
|
alpha2: CO
|
@@ -438,9 +433,6 @@ EG:
|
|
438
433
|
alpha3: EGY
|
439
434
|
country_code: '20'
|
440
435
|
fields:
|
441
|
-
locality:
|
442
|
-
label: District
|
443
|
-
required: false
|
444
436
|
city:
|
445
437
|
label: City
|
446
438
|
format:
|
@@ -448,7 +440,7 @@ EG:
|
|
448
440
|
postcode:
|
449
441
|
label: 'Post Code'
|
450
442
|
required: false
|
451
|
-
address_format: "{{address1}}\n{{address2}}\n{{address3}}\n{{
|
443
|
+
address_format: "{{address1}}\n{{address2}}\n{{address3}}\n{{city}}\n{{postcode}}\n{{country}}"
|
452
444
|
EH:
|
453
445
|
name: Western Sahara
|
454
446
|
alpha2: EH
|
@@ -510,18 +502,18 @@ GB:
|
|
510
502
|
alpha3: GBR
|
511
503
|
country_code: '44'
|
512
504
|
fields:
|
513
|
-
locality:
|
514
|
-
label: 'Town'
|
515
|
-
required: false
|
516
505
|
city:
|
517
506
|
label: 'City'
|
518
507
|
format:
|
519
508
|
- upcase
|
509
|
+
region:
|
510
|
+
label: 'County'
|
511
|
+
required: false
|
520
512
|
postcode:
|
521
513
|
label: 'Post Code'
|
522
514
|
format:
|
523
515
|
- upcase
|
524
|
-
address_format: "{{address1}}\n{{address2}}\n{{address3}}\n{{
|
516
|
+
address_format: "{{address1}}\n{{address2}}\n{{address3}}\n{{city}}\n{{county}}\n{{postcode}}\n{{country}}"
|
525
517
|
GD:
|
526
518
|
name: Grenada
|
527
519
|
alpha2: GD
|
@@ -653,14 +645,11 @@ ID:
|
|
653
645
|
alpha3: IDN
|
654
646
|
country_code: '62'
|
655
647
|
fields:
|
656
|
-
locality:
|
657
|
-
label: Suburb
|
658
|
-
required: false
|
659
648
|
city:
|
660
649
|
label: City
|
661
650
|
postcode:
|
662
651
|
label: 'Post Code'
|
663
|
-
address_format: "{{address1}}\n{{address2}}\n{{address3}}\n{{
|
652
|
+
address_format: "{{address1}}\n{{address2}}\n{{address3}}\n{{city}} {{postcode}}\n{{country}}"
|
664
653
|
IE:
|
665
654
|
name: Ireland
|
666
655
|
alpha2: IE
|
@@ -907,14 +896,11 @@ MK:
|
|
907
896
|
alpha3: MKD
|
908
897
|
country_code: '389'
|
909
898
|
fields:
|
910
|
-
locality:
|
911
|
-
label: Suburb
|
912
|
-
required: false
|
913
899
|
city:
|
914
900
|
label: City
|
915
901
|
postcode:
|
916
902
|
label: 'Post Code'
|
917
|
-
address_format: "{{address1}}\n{{address2}}\n{{address3}}\n{{
|
903
|
+
address_format: "{{address1}}\n{{address2}}\n{{address3}}\n{{postcode}} {{city}}\n{{country}}"
|
918
904
|
ML:
|
919
905
|
name: Mali
|
920
906
|
alpha2: ML
|
@@ -1061,14 +1047,14 @@ NZ:
|
|
1061
1047
|
alpha3: NZL
|
1062
1048
|
country_code: '64'
|
1063
1049
|
fields:
|
1064
|
-
|
1050
|
+
city:
|
1065
1051
|
label: Suburb
|
1066
1052
|
required: false
|
1067
|
-
|
1068
|
-
label: City
|
1053
|
+
region:
|
1054
|
+
label: Town/City
|
1069
1055
|
postcode:
|
1070
1056
|
label: 'Post Code'
|
1071
|
-
address_format: "{{address1}}\n{{address2}}\n{{address3}}\n{{
|
1057
|
+
address_format: "{{address1}}\n{{address2}}\n{{address3}}\n{{city}}\n{{region}} {{postcode}}\n{{country}}"
|
1072
1058
|
OM:
|
1073
1059
|
name: Oman
|
1074
1060
|
alpha2: OM
|
@@ -1135,14 +1121,11 @@ PT:
|
|
1135
1121
|
alpha3: PRT
|
1136
1122
|
country_code: '351'
|
1137
1123
|
fields:
|
1138
|
-
locality:
|
1139
|
-
label: Village
|
1140
|
-
required: false
|
1141
1124
|
city:
|
1142
1125
|
label: City
|
1143
1126
|
postcode:
|
1144
1127
|
label: 'Post Code'
|
1145
|
-
address_format: "{{address1}}\n{{address2}}\n{{address3}}\n{{
|
1128
|
+
address_format: "{{address1}}\n{{address2}}\n{{address3}}\n{{postcode}} {{city}}\n{{country}}"
|
1146
1129
|
PW:
|
1147
1130
|
name: Palau
|
1148
1131
|
alpha2: PW
|
@@ -1480,7 +1463,7 @@ WS:
|
|
1480
1463
|
label: City
|
1481
1464
|
format:
|
1482
1465
|
- upcase
|
1483
|
-
address_format: "{{address1}}\n{{address2}}\n{{address3}}\n{{city}}\n{{
|
1466
|
+
address_format: "{{address1}}\n{{address2}}\n{{address3}}\n{{city}}\n{{country}}"
|
1484
1467
|
YE:
|
1485
1468
|
name: Yemen
|
1486
1469
|
alpha2: YE
|
@@ -1497,16 +1480,12 @@ ZA:
|
|
1497
1480
|
alpha3: ZAF
|
1498
1481
|
country_code: '27'
|
1499
1482
|
fields:
|
1500
|
-
locality:
|
1501
|
-
label: Suburb
|
1502
|
-
format:
|
1503
|
-
- upcase
|
1504
1483
|
city:
|
1505
1484
|
label: City
|
1506
1485
|
region:
|
1507
1486
|
label: Province
|
1508
1487
|
required: false
|
1509
|
-
address_format: "{{address1}}\n{{address2}}\n{{address3}}\n{{
|
1488
|
+
address_format: "{{address1}}\n{{address2}}\n{{address3}}\n{{city}}\n{{region}}\n{postcode}}\n{{country}}"
|
1510
1489
|
ZM:
|
1511
1490
|
name: Zambia
|
1512
1491
|
alpha2: ZM
|
data/lib/worldly/country.rb
CHANGED
@@ -34,7 +34,7 @@ module Worldly
|
|
34
34
|
end
|
35
35
|
|
36
36
|
# Generate an address for printing based on the countries address format.
|
37
|
-
# attributes = {address1: '12 hey St', address2: '',
|
37
|
+
# attributes = {address1: '12 hey St', address2: '', city: 'Homeville', postcode: 'AHZ 312' }
|
38
38
|
# sending country = 'AU'. If added the country name will be excluded from address
|
39
39
|
def to_print(attributes, sending_country=nil)
|
40
40
|
# don't add country if sending from country
|
@@ -51,6 +51,24 @@ module Worldly
|
|
51
51
|
.strip
|
52
52
|
end
|
53
53
|
|
54
|
+
# Generate an address for printing based on the countries address format.
|
55
|
+
# attributes = {address1: '12 hey St', address2: '', city: 'Homeville', postcode: 'AHZ 312' }
|
56
|
+
# sending country = 'AU'. If added the country name will be excluded from address
|
57
|
+
def to_display(attributes, sending_country=nil)
|
58
|
+
# don't add country if sending from country
|
59
|
+
unless sending_country.to_s.upcase == @code
|
60
|
+
attributes.merge!({ country: name})
|
61
|
+
end
|
62
|
+
print = address_format.dup
|
63
|
+
all_fields.each do |f|
|
64
|
+
print.gsub!("{{#{f}}}", format_values(f, attributes[f].to_s, ignore_rules: ['upcase']) )
|
65
|
+
end
|
66
|
+
print.squeeze(' ')
|
67
|
+
.gsub(/\A\s+\n|\n\s+|\s+\n\s+\Z/, "\n")
|
68
|
+
.squeeze("\n")
|
69
|
+
.strip
|
70
|
+
end
|
71
|
+
|
54
72
|
def has_field?(f)
|
55
73
|
fields.key?(f)
|
56
74
|
end
|
@@ -127,13 +145,18 @@ module Worldly
|
|
127
145
|
# Format a value e.g :region, 'NY'
|
128
146
|
# apply any formatting rules
|
129
147
|
# - if rule fullname included change the region to it's full name - New York
|
130
|
-
|
148
|
+
# options = ignore_rules: ['upcase']
|
149
|
+
def format_values(field, value, options={})
|
131
150
|
value = value.dup
|
132
151
|
value.to_s.strip!
|
133
152
|
if !fields.key?(field) || fields[field][:format].nil?
|
134
153
|
return value
|
135
154
|
end
|
136
155
|
rules = fields[field][:format].dup
|
156
|
+
# ignore rules
|
157
|
+
if options[:ignore_rules]
|
158
|
+
rules = rules - options[:ignore_rules]
|
159
|
+
end
|
137
160
|
# use fullname rather than abbreviated
|
138
161
|
# fullname rule must be applied first!
|
139
162
|
if rules.delete('fullname') && regions[value]
|
data/lib/worldly/version.rb
CHANGED
data/worldly.gemspec
CHANGED
@@ -6,7 +6,7 @@ require 'worldly/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "worldly"
|
8
8
|
spec.version = Worldly::VERSION
|
9
|
-
spec.authors = ["
|
9
|
+
spec.authors = ["Adventist Media"]
|
10
10
|
spec.email = ["webmaster@adventistmedia.org.au"]
|
11
11
|
spec.summary = %q{Country address formatting and telephone information}
|
12
12
|
spec.description = %q{Get country address formatting rules and local fields for forms. }
|
@@ -18,6 +18,6 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_development_dependency "bundler", "
|
21
|
+
spec.add_development_dependency "bundler", ">= 2.1.0"
|
22
22
|
spec.add_development_dependency "rake"
|
23
23
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: worldly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
autorequire:
|
7
|
+
- Adventist Media
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.1.0
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.1.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,7 +70,7 @@ homepage: ''
|
|
70
70
|
licenses:
|
71
71
|
- MIT
|
72
72
|
metadata: {}
|
73
|
-
post_install_message:
|
73
|
+
post_install_message:
|
74
74
|
rdoc_options: []
|
75
75
|
require_paths:
|
76
76
|
- lib
|
@@ -85,9 +85,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
85
|
- !ruby/object:Gem::Version
|
86
86
|
version: '0'
|
87
87
|
requirements: []
|
88
|
-
|
89
|
-
|
90
|
-
signing_key:
|
88
|
+
rubygems_version: 3.0.3
|
89
|
+
signing_key:
|
91
90
|
specification_version: 4
|
92
91
|
summary: Country address formatting and telephone information
|
93
92
|
test_files: []
|