worldly 0.1.8 → 0.1.9
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 +2 -0
- data/README.md +10 -0
- data/lib/worldly/country.rb +24 -1
- data/lib/worldly/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb1f6102b4a99fa4c0b05b542f7bdb0e2afe7a17
|
4
|
+
data.tar.gz: fe728dee0952adb4573df76edbbc3ffbb622f3d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 552cc4c1e6e6fad5b7be5f546314b51f3a41dca1fdf7033c785099453c64c4206486fe3f58df60bc4bc6c5ef832e412118d766006f82dbb221c982cb306885bc
|
7
|
+
data.tar.gz: 0e51f4894c1d5ff91870df8e7e5a65bdc61336e3e7a8a616f1ecc42a6ac3030d3a642daefe05cd55a1c802d9cfb081dacb72ca9edf003cbf3f2bc6914143f62f
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -108,6 +108,16 @@ To have the address formatted correctly for mailing use to_print(attributes, sen
|
|
108
108
|
country.to_print({address1: '12 hey St', region:'NSW', postcode: '2000' }, 'AU')
|
109
109
|
=> "12 hey St\nNSW 2000"
|
110
110
|
```
|
111
|
+
|
112
|
+
There is also a to_display method which ignores certain address formatting rules:
|
113
|
+
|
114
|
+
```
|
115
|
+
country.to_print({address1: '12 hey St', address2: '', postcode: '2000', city: 'Newtown', state:'NSW'})
|
116
|
+
=> "12 hey St\nNEWTOWN 2000\nAustralia"
|
117
|
+
country.to_display({address1: '12 hey St', address2: '', postcode: '2000', city: 'Newtown', state:'NSW'})
|
118
|
+
=> "12 hey St\nNewtown 2000\nAustralia"
|
119
|
+
```
|
120
|
+
|
111
121
|
## Contributing
|
112
122
|
|
113
123
|
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/worldly/country.rb
CHANGED
@@ -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: '', locality:'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
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: worldly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Lewis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|