uk_postcode 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +0 -36
- data/lib/uk_postcode/version.rb +3 -0
- data/lib/uk_postcode.rb +6 -2
- data/test/samples/wikipedia.list +0 -1
- data/test/test_uk_postcode.rb +30 -1
- metadata +6 -5
data/Rakefile
CHANGED
@@ -1,44 +1,8 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
require "rake/gempackagetask"
|
3
1
|
require "rake/testtask"
|
4
2
|
|
5
|
-
task :default => [:test]
|
6
|
-
|
7
3
|
Rake::TestTask.new("test") do |t|
|
8
|
-
t.libs << "test"
|
9
4
|
t.pattern = "test/**/test_*.rb"
|
10
5
|
t.verbose = true
|
11
6
|
end
|
12
7
|
|
13
8
|
task :default => :test
|
14
|
-
|
15
|
-
require "rake/testtask"
|
16
|
-
Rake::TestTask.new do |t|
|
17
|
-
t.libs << "test"
|
18
|
-
t.test_files = FileList["test/**/*_test.rb"]
|
19
|
-
t.verbose = true
|
20
|
-
end
|
21
|
-
|
22
|
-
spec = Gem::Specification.new do |s|
|
23
|
-
s.name = "uk_postcode"
|
24
|
-
s.version = "0.0.2"
|
25
|
-
s.summary = "UK postcode parsing and validation"
|
26
|
-
s.author = "Paul Battley"
|
27
|
-
s.email = "pbattley@gmail.com"
|
28
|
-
|
29
|
-
s.has_rdoc = true
|
30
|
-
|
31
|
-
s.files = %w(Rakefile README.md) + Dir.glob("{bin,test,lib}/**/*") - ["test/samples/postzon.list"]
|
32
|
-
s.executables = FileList["bin/**"].map { |f| File.basename(f) }
|
33
|
-
|
34
|
-
s.require_paths = ["lib"]
|
35
|
-
|
36
|
-
s.add_development_dependency("thoughtbot-shoulda")
|
37
|
-
end
|
38
|
-
|
39
|
-
Rake::GemPackageTask.new(spec) do |pkg|
|
40
|
-
pkg.gem_spec = spec
|
41
|
-
end
|
42
|
-
|
43
|
-
desc 'Clear out generated packages'
|
44
|
-
task :clean => [:clobber_package]
|
data/lib/uk_postcode.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
class UKPostcode
|
2
2
|
MATCH = /\A
|
3
|
-
|
3
|
+
\s*
|
4
|
+
( [A-PR-UWYZ01][A-Z01]? ) # area
|
4
5
|
( [0-9IO][0-9A-HJKMNPR-YIO]? ) # district
|
5
6
|
(?:
|
6
|
-
\s
|
7
|
+
\s*
|
7
8
|
( [0-9IO] ) # sector
|
8
9
|
( [ABD-HJLNPQ-Z10]{2} ) # unit
|
9
10
|
)?
|
11
|
+
\s*
|
10
12
|
\Z/x
|
11
13
|
|
12
14
|
attr_reader :raw
|
@@ -100,3 +102,5 @@ private
|
|
100
102
|
s && s.tr("IO", "10")
|
101
103
|
end
|
102
104
|
end
|
105
|
+
|
106
|
+
require "uk_postcode/version"
|
data/test/samples/wikipedia.list
CHANGED
data/test/test_uk_postcode.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- coding: undecided -*-
|
1
2
|
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
2
3
|
require "test/unit"
|
3
4
|
require "shoulda"
|
@@ -164,10 +165,14 @@ class UKPostcodeTest < Test::Unit::TestCase
|
|
164
165
|
end
|
165
166
|
|
166
167
|
context "when used as a string" do
|
167
|
-
should "normalise spacing" do
|
168
|
+
should "normalise spacing when no spacing has been used in the input" do
|
168
169
|
assert_equal "W1A 1AA", UKPostcode.new("W1A1AA").norm
|
169
170
|
end
|
170
171
|
|
172
|
+
should "normalise spacing when too much spacing has been used in the input" do
|
173
|
+
assert_equal "W1A 1AA", UKPostcode.new("W1A 1AA").norm
|
174
|
+
end
|
175
|
+
|
171
176
|
should "convert case" do
|
172
177
|
assert_equal "W1A 1AA", UKPostcode.new("w1a 1aa").norm
|
173
178
|
end
|
@@ -175,6 +180,10 @@ class UKPostcodeTest < Test::Unit::TestCase
|
|
175
180
|
should "ignore a missing incode" do
|
176
181
|
assert_equal "W1A", UKPostcode.new("W1A").norm
|
177
182
|
end
|
183
|
+
|
184
|
+
should "trim whitespace from start and end of the string" do
|
185
|
+
assert_equal "W1A 1AA", UKPostcode.new(" W1A 1AA ").norm
|
186
|
+
end
|
178
187
|
end
|
179
188
|
|
180
189
|
should "return original input for to_s" do
|
@@ -210,4 +219,24 @@ class UKPostcodeTest < Test::Unit::TestCase
|
|
210
219
|
end
|
211
220
|
end
|
212
221
|
end
|
222
|
+
|
223
|
+
context "when digits are used instead of letters" do
|
224
|
+
context "in a full postcode" do
|
225
|
+
setup do
|
226
|
+
@postcode = UKPostcode.new("0X1 0AB")
|
227
|
+
end
|
228
|
+
|
229
|
+
should "be valid" do
|
230
|
+
assert @postcode.valid?
|
231
|
+
end
|
232
|
+
|
233
|
+
should "be full" do
|
234
|
+
assert @postcode.full?
|
235
|
+
end
|
236
|
+
|
237
|
+
should "normalise to letters" do
|
238
|
+
assert_equal "OX1 0AB", @postcode.norm
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
213
242
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uk_postcode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Battley
|
@@ -9,11 +9,11 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01
|
12
|
+
date: 2010-06-01 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
16
|
+
name: shoulda
|
17
17
|
type: :development
|
18
18
|
version_requirement:
|
19
19
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -33,12 +33,13 @@ extra_rdoc_files: []
|
|
33
33
|
files:
|
34
34
|
- Rakefile
|
35
35
|
- README.md
|
36
|
-
- test/samples/wikipedia.list
|
37
36
|
- test/test_samples.rb
|
38
37
|
- test/test_uk_postcode.rb
|
38
|
+
- test/samples/wikipedia.list
|
39
39
|
- lib/uk_postcode.rb
|
40
|
+
- lib/uk_postcode/version.rb
|
40
41
|
has_rdoc: true
|
41
|
-
homepage:
|
42
|
+
homepage: http://github.com/threedaymonk/uk_postcode
|
42
43
|
licenses: []
|
43
44
|
|
44
45
|
post_install_message:
|