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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b84b6615e26e6486618cbbdc1596cfea9a9550bf
4
- data.tar.gz: 32d3894a330baced5aaefc58c3ee054e75e1f0ea
3
+ metadata.gz: bb1f6102b4a99fa4c0b05b542f7bdb0e2afe7a17
4
+ data.tar.gz: fe728dee0952adb4573df76edbbc3ffbb622f3d7
5
5
  SHA512:
6
- metadata.gz: 10d069ed2dd4c0ba8824e475f00e6e3d90a6c3748c7480536d46d554d581792e505e17fbcee97b2175fb178c05e5f9117f121302189cf39107c3b85dd8f05e99
7
- data.tar.gz: 9e8e958ff63ff055140c0793adf181afc231d0b5cea9261690ca52cdeb4dda4a9efcd31cc921aa6b47e238cd56a8f24ea0bd59cf5358263e63ab0db620d3967b
6
+ metadata.gz: 552cc4c1e6e6fad5b7be5f546314b51f3a41dca1fdf7033c785099453c64c4206486fe3f58df60bc4bc6c5ef832e412118d766006f82dbb221c982cb306885bc
7
+ data.tar.gz: 0e51f4894c1d5ff91870df8e7e5a65bdc61336e3e7a8a616f1ecc42a6ac3030d3a642daefe05cd55a1c802d9cfb081dacb72ca9edf003cbf3f2bc6914143f62f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,5 @@
1
+ = Version 0.1.9 - 2016-07-26
2
+ * Improvement: Added to_display method
1
3
  = Version 0.1.8 - 2016-01-20
2
4
  * Improvement: Address line 3 not accepted
3
5
  = Version 0.1.7 - 2015-04-09
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.
@@ -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
- def format_values(field, value)
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]
@@ -1,3 +1,3 @@
1
1
  module Worldly
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
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.8
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-01-20 00:00:00.000000000 Z
11
+ date: 2016-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler