going_postal 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +13 -1
- data/lib/going_postal.rb +44 -3
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -53,11 +53,23 @@ valid? is also available directly on the GoingPostal module.
|
|
53
53
|
format_postcode is aliased as format_post_code, format_zip, format_zipcode, and
|
54
54
|
format_zip_code.
|
55
55
|
|
56
|
+
== Contributing
|
57
|
+
|
58
|
+
Contributions are gladly accepted via pull request. When adding new countries
|
59
|
+
or changing existing logic, please keep the following rules in mind for how the
|
60
|
+
formatter / validator should work:
|
61
|
+
|
62
|
+
* reject something that clearly isn't a postcode;
|
63
|
+
* reject as much as possible as can be done with a simple format check;
|
64
|
+
* do not coerce something that may not be a postcode in to a postcode;
|
65
|
+
* accept badly formatted postcodes (eg wrong case, misplaced spaces/separators);
|
66
|
+
* accept everything that is a postcode.
|
67
|
+
|
56
68
|
== Licence
|
57
69
|
|
58
70
|
(The MIT License)
|
59
71
|
|
60
|
-
Copyright (c)
|
72
|
+
Copyright (c) Global Personals, Ltd.
|
61
73
|
|
62
74
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
63
75
|
of this software and associated documentation files (the "Software"), to deal
|
data/lib/going_postal.rb
CHANGED
@@ -30,9 +30,10 @@
|
|
30
30
|
# GoingPostal.postcode?("sl41eg", "GB") #=> "SL4 1EG"
|
31
31
|
# GoingPostal.postcode?("200378001", "US") #=> "20037-8001"
|
32
32
|
#
|
33
|
-
# Currently supported countries are United Kingdom (GB, UK), United States
|
34
|
-
# Canada (CA), Australia (AU), New Zeland (NZ), South Africa (ZA),
|
35
|
-
#
|
33
|
+
# Currently supported countries are United Kingdom (GB, UK), United States
|
34
|
+
# (US), Canada (CA), Australia (AU), New Zeland (NZ), South Africa (ZA), The
|
35
|
+
# Netherlands (NL), Sweden (SE), Belgium (BE), Austria (AT), Norway (NO),
|
36
|
+
# Germany (DE), Luxembourg (LU), Denmark (DE), France (FR) and Romania (RO).
|
36
37
|
#
|
37
38
|
# Ireland (IE) as well as 60+ other countries that do not use postcodes
|
38
39
|
# - see GoingPostal::COUNTRIES_WITHOUT_POSTCODES - are supported insomuch as,
|
@@ -281,7 +282,23 @@ module GoingPostal
|
|
281
282
|
string = string.to_s.delete(" \t\r\n")
|
282
283
|
string if string =~ /^[1-9][0-9]{3}$/
|
283
284
|
end
|
285
|
+
|
286
|
+
def format_dk_postcode(string)
|
287
|
+
format_ch_postcode(string)
|
288
|
+
end
|
284
289
|
|
290
|
+
def format_be_postcode(string)
|
291
|
+
format_ch_postcode(string)
|
292
|
+
end
|
293
|
+
|
294
|
+
def format_lu_postcode(string)
|
295
|
+
format_ch_postcode(string)
|
296
|
+
end
|
297
|
+
|
298
|
+
def format_at_postcode(string)
|
299
|
+
format_ch_postcode(string)
|
300
|
+
end
|
301
|
+
|
285
302
|
def format_nl_postcode(string)
|
286
303
|
string = string.to_s.upcase.delete(" \t\r\n")
|
287
304
|
string.insert(4, " ") if string.length >= 4
|
@@ -292,7 +309,31 @@ module GoingPostal
|
|
292
309
|
match = /^(\d\d)[^\w]*(\d\d\d)$/.match(string)
|
293
310
|
match.captures.join("-") if match && match[1] && match[2]
|
294
311
|
end
|
312
|
+
|
313
|
+
def format_de_postcode(string)
|
314
|
+
string = string.to_s.upcase.delete(" \t\r\n")
|
315
|
+
string if string =~ /^([0]{1}[1-9]{1}|[1-9]{1}[0-9]{1})[0-9]{3}$/
|
316
|
+
end
|
317
|
+
|
318
|
+
def format_se_postcode(string)
|
319
|
+
string = string.to_s.upcase.delete(" \t\r\n")
|
320
|
+
string if string =~ /^[1-9]{1}[0-9]{4}$/
|
321
|
+
end
|
322
|
+
|
323
|
+
def format_no_postcode(string)
|
324
|
+
string = string.to_s.upcase.delete(" \t\r\n")
|
325
|
+
string if string =~ /^[0-9]{4}$/
|
326
|
+
end
|
327
|
+
|
328
|
+
def format_fr_postcode(string)
|
329
|
+
format_de_postcode(string)
|
330
|
+
end
|
295
331
|
|
332
|
+
def format_ro_postcode(string)
|
333
|
+
string = string.to_s.delete(" \t\r\n")
|
334
|
+
string if string =~ /^[0-9]{6}$/
|
335
|
+
end
|
336
|
+
|
296
337
|
private
|
297
338
|
|
298
339
|
def get_args_for_format_postcode(args)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: going_postal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-01-13 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Post/zip code formatting and validation for the UK, US, CA and more.
|
15
15
|
email: mat@sourcetagsandcodes.com
|