snail 0.5.5 → 0.5.6

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.
@@ -234,93 +234,113 @@ class Snail
234
234
  'Zambia',
235
235
  'Zimbabwe'
236
236
  ]
237
-
238
- # see http://www.columbia.edu/kermit/postal.html#usa
239
- # and http://www.usps.com/ncsc/lookups/usps_abbreviations.html
240
- USA_STATES = {
241
- "Alabama" => "AL",
242
- "Alaska" => "AK",
243
- "Arizona" => "AZ",
244
- "Arkansas" => "AR",
245
- "California" => "CA",
246
- "Colorado" => "CO",
247
- "Connecticut" => "CT",
248
- "Delaware" => "DE",
249
- "District Of Columbia" => "DC",
250
- "Florida" => "FL",
251
- "Georgia" => "GA",
252
- "Hawaii" => "HI",
253
- "Idaho" => "ID",
254
- "Illinois" => "IL",
255
- "Indiana" => "IN",
256
- "Iowa" => "IA",
257
- "Kansas" => "KS",
258
- "Kentucky" => "KY",
259
- "Louisiana" => "LA",
260
- "Maine" => "ME",
261
- "Maryland" => "MD",
262
- "Massachusetts" => "MA",
263
- "Michigan" => "MI",
264
- "Minnesota" => "MN",
265
- "Mississippi" => "MS",
266
- "Missouri" => "MO",
267
- "Montana" => "MT",
268
- "Nebraska" => "NE",
269
- "Nevada" => "NV",
270
- "New Hampshire" => "NH",
271
- "New Jersey" => "NJ",
272
- "New Mexico" => "NM",
273
- "New York" => "NY",
274
- "North Carolina" => "NC",
275
- "North Dakota" => "ND",
276
- "Ohio" => "OH",
277
- "Oklahoma" => "OK",
278
- "Oregon" => "OR",
279
- "Pennsylvania" => "PA",
280
- "Rhode Island" => "RI",
281
- "South Carolina" => "SC",
282
- "South Dakota" => "SD",
283
- "Tennessee" => "TN",
284
- "Texas" => "TX",
285
- "Utah" => "UT",
286
- "Vermont" => "VT",
287
- "Virginia" => "VA",
288
- "Washington" => "WA",
289
- "West Virginia" => "WV",
290
- "Wisconsin" => "WI",
291
- "Wyoming" => "WY",
292
237
 
293
- # These are not states exactly, but they are addressed as states through USA
294
- "American Samoa" => "AS",
295
- "Federated States Of Micronesia" => "FM",
296
- "Guam" => "GU",
297
- "Marshall Islands" => "MH",
298
- "Northern Mariana Islands" => "MP",
299
- "Palau" => "PW",
300
- "Puerto Rico" => "PR",
301
- "Virgin Islands" => "VI",
302
- "Armed Forces Africa" => "AE",
303
- "Armed Forces Americas (Except Canada)" => "AA",
304
- "Armed Forces Canada" => "AE",
305
- "Armed Forces Europe" => "AE",
306
- "Armed Forces Middle East" => "AE",
307
- "Armed Forces Pacific" => "AP",
308
- }
238
+ REGIONS = {
239
+ # see http://en.wikipedia.org/wiki/Postcodes_in_Australia#Australia_States_and_territories
240
+ :au => {
241
+ "Australian Capital Territory" => "ACT",
242
+ "New South Wales" => "NSW",
243
+ "Victoria" => "VIC",
244
+ "Queensland" => "QLD",
245
+ "South Australia" => "SA",
246
+ "Western Australia" => "WA",
247
+ "Tasmania" => "TAS",
248
+ "Northern Territory" => "NT"
249
+ },
250
+ # see http://en.wikipedia.org/wiki/Canadian_subnational_postal_abbreviations
251
+ :ca => {
252
+ "Alberta" => "AB",
253
+ "British Columbia" => "BC",
254
+ "Manitoba" => "MB",
255
+ "New Brunswick" => "NB",
256
+ "Newfoundland and Labrador" => "NL",
257
+ "Nova Scotia" => "NS",
258
+ "Northwest Territories" => "NT",
259
+ "Nunavut" => "NU",
260
+ "Ontario" => "ON",
261
+ "Prince Edward Island" => "PE",
262
+ "Quebec" => "QC",
263
+ "Saskatchewan" => "SK",
264
+ "Yukon" => "YT"
265
+ },
266
+ # see http://www.columbia.edu/kermit/postal.html#usa
267
+ # and http://www.usps.com/ncsc/lookups/usps_abbreviations.html
268
+ :us => {
269
+ "Alabama" => "AL",
270
+ "Alaska" => "AK",
271
+ "Arizona" => "AZ",
272
+ "Arkansas" => "AR",
273
+ "California" => "CA",
274
+ "Colorado" => "CO",
275
+ "Connecticut" => "CT",
276
+ "Delaware" => "DE",
277
+ "District Of Columbia" => "DC",
278
+ "Florida" => "FL",
279
+ "Georgia" => "GA",
280
+ "Hawaii" => "HI",
281
+ "Idaho" => "ID",
282
+ "Illinois" => "IL",
283
+ "Indiana" => "IN",
284
+ "Iowa" => "IA",
285
+ "Kansas" => "KS",
286
+ "Kentucky" => "KY",
287
+ "Louisiana" => "LA",
288
+ "Maine" => "ME",
289
+ "Maryland" => "MD",
290
+ "Massachusetts" => "MA",
291
+ "Michigan" => "MI",
292
+ "Minnesota" => "MN",
293
+ "Mississippi" => "MS",
294
+ "Missouri" => "MO",
295
+ "Montana" => "MT",
296
+ "Nebraska" => "NE",
297
+ "Nevada" => "NV",
298
+ "New Hampshire" => "NH",
299
+ "New Jersey" => "NJ",
300
+ "New Mexico" => "NM",
301
+ "New York" => "NY",
302
+ "North Carolina" => "NC",
303
+ "North Dakota" => "ND",
304
+ "Ohio" => "OH",
305
+ "Oklahoma" => "OK",
306
+ "Oregon" => "OR",
307
+ "Pennsylvania" => "PA",
308
+ "Rhode Island" => "RI",
309
+ "South Carolina" => "SC",
310
+ "South Dakota" => "SD",
311
+ "Tennessee" => "TN",
312
+ "Texas" => "TX",
313
+ "Utah" => "UT",
314
+ "Vermont" => "VT",
315
+ "Virginia" => "VA",
316
+ "Washington" => "WA",
317
+ "West Virginia" => "WV",
318
+ "Wisconsin" => "WI",
319
+ "Wyoming" => "WY",
309
320
 
310
- # see http://en.wikipedia.org/wiki/Canadian_subnational_postal_abbreviations
311
- CA_PROVINCES = {
312
- "Alberta" => "AB",
313
- "British Columbia" => "BC",
314
- "Manitoba" => "MB",
315
- "New Brunswick" => "NB",
316
- "Newfoundland and Labrador" => "NL",
317
- "Nova Scotia" => "NS",
318
- "Northwest Territories" => "NT",
319
- "Nunavut" => "NU",
320
- "Ontario" => "ON",
321
- "Prince Edward Island" => "PE",
322
- "Quebec" => "QC",
323
- "Saskatchewan" => "SK",
324
- "Yukon" => "YT"
321
+ # These are not states exactly, but they are addressed as states through USA
322
+ "American Samoa" => "AS",
323
+ "Federated States Of Micronesia" => "FM",
324
+ "Guam" => "GU",
325
+ "Marshall Islands" => "MH",
326
+ "Northern Mariana Islands" => "MP",
327
+ "Palau" => "PW",
328
+ "Puerto Rico" => "PR",
329
+ "Virgin Islands" => "VI",
330
+ "Armed Forces Africa" => "AE",
331
+ "Armed Forces Americas (Except Canada)" => "AA",
332
+ "Armed Forces Canada" => "AE",
333
+ "Armed Forces Europe" => "AE",
334
+ "Armed Forces Middle East" => "AE",
335
+ "Armed Forces Pacific" => "AP",
336
+ }
325
337
  }
338
+
339
+
340
+ # Deprecated
341
+ USA_STATES = REGIONS[:us]
342
+ CA_PROVINCES = REGIONS[:ca]
343
+ AU_REGIONS = REGIONS[:au]
344
+
345
+
326
346
  end
data/lib/snail_helpers.rb CHANGED
@@ -2,8 +2,15 @@ module SnailHelpers
2
2
  def usps_country_options_for_select(selected = nil, default_selected = 'USA')
3
3
  options_for_select(Snail::USPS_COUNTRIES, selected || default_selected)
4
4
  end
5
-
5
+
6
+ def region_options_for_select(country = :us, selected = nil)
7
+ options_for_select(Snail::REGIONS[country], selected)
8
+ end
9
+
10
+ # Deprecated
6
11
  def usa_state_options_for_select(selected = nil)
7
- options_for_select(Snail::USA_STATES, selected)
12
+ region_options_for_select(:us, selected)
8
13
  end
14
+
15
+
9
16
  end
data/test/snail_test.rb CHANGED
@@ -9,50 +9,56 @@ class SnailTest < ActiveSupport::TestCase
9
9
  test "provides USPS country names" do
10
10
  assert Snail.const_defined?('USPS_COUNTRIES')
11
11
  end
12
-
12
+
13
13
  test "provides USA state names with abbreviations" do
14
14
  assert Snail.const_defined?('USA_STATES')
15
15
  assert_equal 'MN', Snail::USA_STATES['Minnesota']
16
16
  end
17
-
17
+
18
18
  test "USA states include territories and islands" do
19
19
  assert Snail::USA_STATES['Guam']
20
20
  end
21
21
 
22
+ test "provides region codes via 2-digit iso country code" do
23
+ assert_equal "WA", Snail::REGIONS[:us]["Washington"]
24
+ assert_equal "WA", Snail::REGIONS[:au]["Western Australia"]
25
+ assert_equal "BC", Snail::REGIONS[:ca]["British Columbia"]
26
+ end
27
+
22
28
  ##
23
29
  ## Configuration
24
30
  ##
25
-
31
+
26
32
  test "initializes from a hash" do
27
33
  s = Snail.new(:name => "John Doe", :city => "Somewheres")
28
34
  assert_equal 'John Doe', s.name
29
35
  assert_equal 'Somewheres', s.city
30
36
  end
31
-
37
+
32
38
  test "aliases common city synonyms" do
33
39
  assert_equal Snail.new(:town => "Somewheres").city, Snail.new(:city => "Somewheres").city
34
40
  end
35
-
41
+
36
42
  test "aliases common region synonyms" do
37
43
  assert_equal Snail.new(:state => "Somewheres").region, Snail.new(:region => "Somewheres").region
38
44
  assert_equal Snail.new(:province => "Somewheres").region, Snail.new(:region => "Somewheres").region
39
45
  end
40
-
46
+
41
47
  test "aliases common postal code synonyms" do
42
48
  assert_equal Snail.new(:zip => "12345").postal_code, Snail.new(:postal_code => "12345").postal_code
43
49
  assert_equal Snail.new(:zip_code => "12345").postal_code, Snail.new(:postal_code => "12345").postal_code
44
50
  assert_equal Snail.new(:postcode => "12345").postal_code, Snail.new(:postal_code => "12345").postal_code
45
51
  end
46
-
52
+
47
53
  ##
48
54
  ## Formatting
49
55
  ##
50
-
56
+
51
57
  test "includes two spaces between region and zip for domestic mail" do
52
58
  s = Snail.new(@us)
53
59
  assert /NY 12345/, s.city_line
54
60
  end
55
-
61
+
56
62
  test "does not include country name for domestic addresses" do
57
63
  s = Snail.new(@us)
58
64
  assert !s.to_s.match(/United States/i)
@@ -64,7 +70,7 @@ class SnailTest < ActiveSupport::TestCase
64
70
  assert !s.to_s.match(/Canada/i)
65
71
  Snail.home_country = "USA"
66
72
  end
67
-
73
+
68
74
  test "includes country name for international addresses" do
69
75
  s = Snail.new(@ca)
70
76
  assert s.to_s.match(/Canada/i)
@@ -74,22 +80,22 @@ class SnailTest < ActiveSupport::TestCase
74
80
  s = Snail.new(@ca.merge(:country => nil))
75
81
  assert s.to_s[-5,5] == "12345"
76
82
  end
77
-
83
+
78
84
  test "country names are uppercased" do
79
85
  s = Snail.new(@ca)
80
86
  assert s.to_s.match(/CANADA/)
81
87
  end
82
-
88
+
83
89
  test "empty lines are removed" do
84
90
  s = Snail.new(@us.merge(:line_1 => ""))
85
91
  assert !s.to_s.match(/^$/)
86
92
  end
87
-
93
+
88
94
  test "to_s" do
89
95
  s = Snail.new(@ca)
90
96
  assert_equal "John Doe\n12345 5th St\nSomewheres NY 12345\nCANADA", s.to_s
91
97
  end
92
-
98
+
93
99
  test "to_html" do
94
100
  s = Snail.new(@ca)
95
101
  s.name = 'John & Jane Doe'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snail
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 5
10
- version: 0.5.5
9
+ - 6
10
+ version: 0.5.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Lance Ivy
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-14 00:00:00 -07:00
18
+ date: 2011-08-21 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies: []
21
21