snail 0.8.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c1cb99969310c1c08d9eef5146e5d5f68a1ede29
4
- data.tar.gz: 8964a79612336d7ab86e78bb118df92769e49c55
3
+ metadata.gz: 69299ca47862ebd3ed450e287deafcf5a89175fa
4
+ data.tar.gz: c582b6d1c0d07674c12307bdc76a001c1976d48e
5
5
  SHA512:
6
- metadata.gz: b590cb20875b4b46e87c8d004bd099484fe9612ddb5c3e0d7ea1768b9cd45b644bb2aa659b6ead0255e87f9b894de834807b29f163f30cfa962d9cc83d0b3f99
7
- data.tar.gz: 0d9cde988655502db980d579b8ce4bbc2988fb2b15a8c0c19e09fe448273bf09199b0de51a33c5b4bd724699dac023efb943e0e50aaf94bd31b5ac76e6a618fd
6
+ metadata.gz: 28db2ac9d411e136359ba5bc3bfe4676856e5aba38f197bb2c3729cb64f276bd562e51267c125915432f1f5cd4c5981b28be65b42a47a770a3dde676cf9d5b5e
7
+ data.tar.gz: acfa11f47bd78a8a4c0671fefa24a0ab2ac0b9f47e715124e5a677840e0588087436073936da30de69bd4313dd9b1f6d30c6d09a13dd4ad6f6ccf6cf5161dec1
@@ -1,240 +1,7 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
+ # TODO: carmen
3
4
  class Snail
4
- # based on http://www.columbia.edu/kermit/postal.html#index, which is in turn based on
5
- # the USPS International Mailing Manual. See also http://www.25thandclement.com/~william/USPS_ICL.html.
6
- USPS_COUNTRIES = [
7
- 'Afghanistan',
8
- 'Albania',
9
- 'Algeria',
10
- 'Andorra',
11
- 'Angola',
12
- 'Anguilla',
13
- 'Antigua and Barbuda',
14
- 'Argentina',
15
- 'Armenia',
16
- 'Aruba',
17
- 'Ascension',
18
- 'Australia',
19
- 'Austria',
20
- 'Azerbaijan',
21
- 'Bahamas',
22
- 'Bahrain',
23
- 'Bangladesh',
24
- 'Barbados',
25
- 'Belarus',
26
- 'Belgium',
27
- 'Belize',
28
- 'Benin',
29
- 'Bermuda',
30
- 'Bhutan',
31
- 'Bolivia',
32
- 'Bosnia and Herzegovina',
33
- 'Botswana',
34
- 'Brazil',
35
- 'British Virgin Islands',
36
- 'Brunei Darussalam',
37
- 'Bulgaria',
38
- 'Burkina Faso',
39
- 'Burundi',
40
- 'Cambodia',
41
- 'Cameroon',
42
- 'Canada',
43
- 'Canary Islands',
44
- 'Cape Verde',
45
- 'Cayman Islands',
46
- 'Central African Republic',
47
- 'Chad',
48
- 'Chile',
49
- 'China',
50
- 'Colombia',
51
- 'Comoros',
52
- 'Costa Rica',
53
- 'CÔte D\'ivoire',
54
- 'Croatia',
55
- 'Cuba',
56
- 'Curacao',
57
- 'Cyprus',
58
- 'Czech Republic',
59
- 'Democratic Republic of the Congo',
60
- 'Denmark',
61
- 'Djibouti',
62
- 'Dominica',
63
- 'Dominican Republic',
64
- 'East Timor',
65
- 'Ecuador',
66
- 'Egypt',
67
- 'El Salvador',
68
- 'England',
69
- 'Equatorial Guinea',
70
- 'Eritrea',
71
- 'Estonia',
72
- 'Ethiopia',
73
- 'Falkland Islands',
74
- 'Faroe Islands',
75
- 'Fiji',
76
- 'Finland',
77
- 'France',
78
- 'French Guiana',
79
- 'French Polynesia',
80
- 'Gabon',
81
- 'Gambia',
82
- 'Georgia',
83
- 'Germany',
84
- 'Ghana',
85
- 'Gibraltar',
86
- 'Greece',
87
- 'Greenland',
88
- 'Grenada',
89
- 'Guadeloupe',
90
- 'Guatemala',
91
- 'Guinea',
92
- 'Guinea-Bissau',
93
- 'Guyana',
94
- 'Haiti',
95
- 'Honduras',
96
- 'Hong Kong',
97
- 'Hungary',
98
- 'Iceland',
99
- 'India',
100
- 'Indonesia',
101
- 'Iran',
102
- 'Iraq',
103
- 'Ireland',
104
- 'Isle of Man',
105
- 'Israel',
106
- 'Italy',
107
- 'Jamaica',
108
- 'Japan',
109
- 'Jordan',
110
- 'Kazakhstan',
111
- 'Kenya',
112
- 'Kiribati',
113
- 'Korea',
114
- 'Kosovo',
115
- 'Kuwait',
116
- 'Kyrgyzstan',
117
- 'Laos',
118
- 'Latvia',
119
- 'Lebanon',
120
- 'Lesotho',
121
- 'Liberia',
122
- 'Libya',
123
- 'Liechtenstein',
124
- 'Lithuania',
125
- 'Luxembourg',
126
- 'Macao',
127
- 'Macedonia',
128
- 'Madagascar',
129
- 'Malawi',
130
- 'Malaysia',
131
- 'Maldives',
132
- 'Mali',
133
- 'Malta',
134
- 'Martinique',
135
- 'Mauritania',
136
- 'Mauritius',
137
- 'Mayotte',
138
- 'Mexico',
139
- 'Moldova',
140
- 'Monaco',
141
- 'Mongolia',
142
- 'Montenegro',
143
- 'Montserrat',
144
- 'Morocco',
145
- 'Mozambique',
146
- 'Myanmar',
147
- 'Namibia',
148
- 'Nauru',
149
- 'Nepal',
150
- 'Netherlands',
151
- 'Netherlands Antilles',
152
- 'New Caledonia',
153
- 'New Zealand',
154
- 'Nicaragua',
155
- 'Niger',
156
- 'Nigeria',
157
- 'North Korea',
158
- 'Northern Ireland',
159
- 'Norway',
160
- 'Oman',
161
- 'Pakistan',
162
- 'Palestinian Territory',
163
- 'Panama',
164
- 'Papua New Guinea',
165
- 'Paraguay',
166
- 'Peru',
167
- 'Philippines',
168
- 'Pitcairn Island',
169
- 'Poland',
170
- 'Portugal',
171
- 'Qatar',
172
- 'Republic of the Congo',
173
- 'Reunion',
174
- 'Romania',
175
- 'Russian Federation',
176
- 'Rwanda',
177
- 'Saint Helena',
178
- 'Saint Kitts and Nevis',
179
- 'Saint Lucia',
180
- 'Saint Pierre and Miquelon',
181
- 'Saint Vincent and the Grenadines',
182
- 'San Marino',
183
- 'Sao Tome and Principe',
184
- 'Saudi Arabia',
185
- 'Scotland',
186
- 'Senegal',
187
- 'Serbia',
188
- 'Seychelles',
189
- 'Sierra Leone',
190
- 'Singapore',
191
- 'Slovak Republic',
192
- 'Slovenia',
193
- 'Solomon Islands',
194
- 'Somalia',
195
- 'South Africa',
196
- 'South Georgia',
197
- 'South Sudan',
198
- 'Spain',
199
- 'Sri Lanka',
200
- 'Sudan',
201
- 'Suriname',
202
- 'Swaziland',
203
- 'Sweden',
204
- 'Switzerland',
205
- 'Syria',
206
- 'Taiwan',
207
- 'Tajikistan',
208
- 'Tanzania',
209
- 'Thailand',
210
- 'Togo',
211
- 'Tonga',
212
- 'Trinidad and Tobago',
213
- 'Tristan da Cunha',
214
- 'Tunisia',
215
- 'Turkey',
216
- 'Turkmenistan',
217
- 'Turks and Caicos Islands',
218
- 'Tuvalu',
219
- 'Uganda',
220
- 'Ukraine',
221
- 'United Arab Emirates',
222
- 'United Kingdom',
223
- 'Uruguay',
224
- 'USA',
225
- 'Uzbekistan',
226
- 'Vanuatu',
227
- 'Vatican City',
228
- 'Venezuela',
229
- 'Vietnam',
230
- 'Wales',
231
- 'Wallis and Futuna Islands',
232
- 'Western Samoa',
233
- 'Western Sahara',
234
- 'Yemen',
235
- 'Zambia',
236
- 'Zimbabwe'
237
- ]
238
5
 
239
6
  REGIONS = {
240
7
  # see http://en.wikipedia.org/wiki/Postcodes_in_Australia#Australia_States_and_territories
@@ -337,12 +104,6 @@ class Snail
337
104
  }
338
105
  }
339
106
 
340
-
341
- # Deprecated
342
- USA_STATES = REGIONS[:us]
343
- CA_PROVINCES = REGIONS[:ca]
344
- AU_REGIONS = REGIONS[:au]
345
-
346
107
  module Iso3166
347
108
  # as of January 28, 2013
348
109
  # pulled http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
@@ -604,13 +365,13 @@ class Snail
604
365
  'ZM' => ["ZAMBIA"],
605
366
  'ZW' => ["ZIMBABWE"]
606
367
  }
607
-
368
+
608
369
  ALPHA2_EXCEPTIONS = {
609
370
  'UK' => 'GB', # great britain aka united kingdom
610
371
  'FX' => 'FR', # france
611
372
  'SU' => 'RU' # russia
612
373
  }
613
-
374
+
614
375
  ALPHA3_TO_ALPHA2 = {
615
376
  "ABW" => "AW",
616
377
  "AFG" => "AF",
@@ -1,5 +1,5 @@
1
1
  class Snail
2
- module Configurable
2
+ module Initializable
3
3
  def initialize(attrs = {}, &block)
4
4
  attrs.each do |k, v|
5
5
  m = "#{k}="
@@ -12,5 +12,4 @@ class Snail
12
12
  yield self if block_given?
13
13
  end
14
14
  end
15
- include Configurable
16
15
  end
data/lib/snail/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Snail
2
- VERSION = '0.8.0'
2
+ VERSION = '1.0.1'
3
3
  end
data/lib/snail.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # -*- encoding : utf-8 -*-
2
- require 'snail/configurable'
2
+ require 'snail/initializable'
3
3
  require 'snail/constants'
4
4
  require 'snail_helpers'
5
5
 
@@ -11,7 +11,7 @@ if defined? ActionView
11
11
  end
12
12
 
13
13
  class Snail
14
- include Configurable
14
+ include Snail::Initializable
15
15
 
16
16
  # this will be raised whenever formatting or validation is run on an unsupported or unknown country
17
17
  class UnknownCountryError < ArgumentError; end
@@ -63,14 +63,21 @@ class Snail
63
63
  iso
64
64
  elsif iso = ::Snail::Iso3166::ALPHA3_TO_ALPHA2[val]
65
65
  iso
66
- elsif iso_pair = ::Snail::Iso3166::ALPHA2.find { |a2, names| names.include?(val) }
67
- ActiveSupport::Deprecation.warn("Country name lookup will be deprecated in the near future. Please pass ISO3166 country codes to Snail instead.", caller)
68
- iso_pair.first
69
66
  else
70
67
  nil
71
68
  end
72
69
  end
73
70
 
71
+ # Where the mail is coming from.
72
+ def origin=(val)
73
+ @origin = Snail.lookup_country_iso(val)
74
+ end
75
+
76
+ # Where the mail is coming from. Defaults to the global `home_country`.
77
+ def origin
78
+ @origin ||= Snail.home_country
79
+ end
80
+
74
81
  # Store country as ISO-3166 Alpha 2
75
82
  def country=(val)
76
83
  @country = Snail.lookup_country_iso(val)
@@ -136,8 +143,8 @@ class Snail
136
143
  end
137
144
  end
138
145
 
139
- # TODO after country name lookup deprecation, add localized country names to this
146
+ # TODO localize to the origin country
140
147
  def country_line
141
- ::Snail::Iso3166::ALPHA2[country].first if country and self.class.home_country != country
148
+ ::Snail::Iso3166::ALPHA2[country].first if country and self.origin != country
142
149
  end
143
150
  end
data/lib/snail_helpers.rb CHANGED
@@ -1,16 +1,7 @@
1
1
  module SnailHelpers
2
- def usps_country_options_for_select(selected = nil, default_selected = 'USA')
3
- options_for_select(Snail::USPS_COUNTRIES, selected || default_selected)
4
- end
5
2
 
6
3
  def region_options_for_select(country = :us, selected = nil)
7
4
  options_for_select(Snail::REGIONS[country], selected)
8
5
  end
9
6
 
10
- # Deprecated
11
- def usa_state_options_for_select(selected = nil)
12
- region_options_for_select(:us, selected)
13
- end
14
-
15
-
16
7
  end
data/snail.gemspec CHANGED
@@ -13,5 +13,5 @@ Gem::Specification.new do |s|
13
13
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
14
14
  s.require_paths = ["lib"]
15
15
 
16
- s.add_dependency "active_support"
16
+ s.add_dependency "activesupport"
17
17
  end
data/test/snail_test.rb CHANGED
@@ -6,19 +6,6 @@ class SnailTest < ActiveSupport::TestCase
6
6
  @ca = {:name => "John Doe", :line_1 => "12345 5th St", :city => "Somewheres", :state => "NY", :zip => "12345", :country => 'CAN'}
7
7
  end
8
8
 
9
- test "provides USPS country names" do
10
- assert Snail.const_defined?('USPS_COUNTRIES')
11
- end
12
-
13
- test "provides USA state names with abbreviations" do
14
- assert Snail.const_defined?('USA_STATES')
15
- assert_equal 'MN', Snail::USA_STATES['Minnesota']
16
- end
17
-
18
- test "USA states include territories and islands" do
19
- assert Snail::USA_STATES['Guam']
20
- end
21
-
22
9
  test "provides region codes via 2-digit iso country code" do
23
10
  assert_equal "WA", Snail::REGIONS[:us]["Washington"]
24
11
  assert_equal "WA", Snail::REGIONS[:au]["Western Australia"]
@@ -59,16 +46,6 @@ class SnailTest < ActiveSupport::TestCase
59
46
  ## Country Normalization
60
47
  ##
61
48
 
62
- test "normalize country name to alpha2" do
63
- s = Snail.new(@ca.merge(:country => 'Slovenia'))
64
- assert_equal "SI", s.country
65
- end
66
-
67
- test "normalize uppercase country name to alpha2" do
68
- s = Snail.new(@ca.merge(:country => 'JAPAN'))
69
- assert_equal "JP", s.country
70
- end
71
-
72
49
  test "normalize alpha3 to alpha2" do
73
50
  s = Snail.new(@ca.merge(:country => 'SVN'))
74
51
  assert_equal "SI", s.country
@@ -94,20 +71,17 @@ class SnailTest < ActiveSupport::TestCase
94
71
  end
95
72
 
96
73
  test "does not include country name for domestic addresses" do
97
- s = Snail.new(@us)
74
+ s = Snail.new(@us.merge(:origin => 'US'))
98
75
  assert !s.to_s.match(/United States/i)
99
- end
100
-
101
- test "does not include country name for domestic addresses in canada" do
102
- Snail.home_country = "Canada"
103
- s = Snail.new(@ca)
76
+ s = Snail.new(@ca.merge(:origin => 'CA'))
104
77
  assert !s.to_s.match(/Canada/i)
105
- Snail.home_country = "USA"
106
78
  end
107
79
 
108
80
  test "includes country name for international addresses" do
109
- s = Snail.new(@ca)
110
- assert s.to_s.match(/Canada\Z/i), s.to_s
81
+ s = Snail.new(@us.merge(:origin => 'CA'))
82
+ assert s.to_s.match(/United States/i)
83
+ s = Snail.new(@ca.merge(:origin => 'US'))
84
+ assert s.to_s.match(/Canada/i)
111
85
  end
112
86
 
113
87
  test "includes first country name for countries with many commonly used names" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lance Ivy
@@ -11,7 +11,7 @@ cert_chain: []
11
11
  date: 2013-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: active_support
14
+ name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - '>='
@@ -36,8 +36,8 @@ files:
36
36
  - README.rdoc
37
37
  - Rakefile
38
38
  - lib/snail.rb
39
- - lib/snail/configurable.rb
40
39
  - lib/snail/constants.rb
40
+ - lib/snail/initializable.rb
41
41
  - lib/snail/version.rb
42
42
  - lib/snail_helpers.rb
43
43
  - snail.gemspec