paf 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/paf.rb +6 -3
- data/lib/paf/attribute.rb +12 -9
- data/lib/paf/core_ext/array.rb +14 -0
- data/lib/paf/core_ext/object.rb +12 -0
- data/lib/paf/{premises → core_ext}/string.rb +2 -2
- data/lib/paf/formattable.rb +6 -25
- data/lib/paf/lineable.rb +27 -0
- data/lib/paf/premises.rb +1 -4
- data/lib/paf/thoroughfare_locality.rb +2 -2
- data/lib/paf/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36b4513b6be17e49ed9962e9aafcdbbb4039ee3d
|
4
|
+
data.tar.gz: 1f2d2a352533a1fcfb6e6d8ccd321f3de40b2c75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 409df603f878fafd0b169d39fc65b26e3419b880d3a3bf8bf857bfff53625fedda83c62d64a629de03117fd22f984cbf13954eefe6414e5d67cfd2ff8e1fb0df
|
7
|
+
data.tar.gz: 00d5ae8fef08d1324f7998b1899451fecb1dc52a9e893f2210020085c12c415905acdd0612f862fed5b2f97079d55dca4e34ca5322498a27d89aac760c3e97b4
|
data/lib/paf.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
require 'paf/version'
|
2
2
|
require 'paf/attribute'
|
3
3
|
require 'paf/formattable'
|
4
|
+
require 'paf/core_ext/object'
|
5
|
+
require 'paf/core_ext/string'
|
6
|
+
require 'paf/core_ext/array'
|
4
7
|
|
5
8
|
# Base class from the elements of a UK Royal Mail Postcode Address File entry
|
6
9
|
class Paf
|
@@ -16,7 +19,7 @@ class Paf
|
|
16
19
|
|
17
20
|
# PO Box number prepended with the string PO BOX
|
18
21
|
def po_box
|
19
|
-
"PO BOX #{po_box_number}" unless po_box_number.
|
22
|
+
"PO BOX #{po_box_number}" unless po_box_number.vacant?
|
20
23
|
end
|
21
24
|
|
22
25
|
# Dependent thoroughfare name and descriptor
|
@@ -32,7 +35,7 @@ class Paf
|
|
32
35
|
private
|
33
36
|
|
34
37
|
def concatenated(attrs)
|
35
|
-
value = attrs.map { |attr| send(attr)
|
36
|
-
value unless value.
|
38
|
+
value = attrs.map { |attr| send(attr) }.condense.join(' ')
|
39
|
+
value unless value.vacant?
|
37
40
|
end
|
38
41
|
end
|
data/lib/paf/attribute.rb
CHANGED
@@ -9,13 +9,19 @@ class Paf
|
|
9
9
|
# Methods to be added to the including class
|
10
10
|
module ClassMethods
|
11
11
|
def attrs
|
12
|
-
|
12
|
+
organisation_attrs +
|
13
|
+
premises_attrs +
|
13
14
|
dependent_thoroughfare_attrs +
|
14
15
|
thoroughfare_attrs +
|
15
16
|
locality_attrs +
|
17
|
+
post_attrs +
|
16
18
|
other_attrs
|
17
19
|
end
|
18
20
|
|
21
|
+
def organisation_attrs
|
22
|
+
%i[organisation_name department_name]
|
23
|
+
end
|
24
|
+
|
19
25
|
def premises_attrs
|
20
26
|
%i[sub_building_name building_name building_number]
|
21
27
|
end
|
@@ -32,15 +38,12 @@ class Paf
|
|
32
38
|
%i[double_dependent_locality dependent_locality]
|
33
39
|
end
|
34
40
|
|
41
|
+
def post_attrs
|
42
|
+
%i[post_town postcode]
|
43
|
+
end
|
44
|
+
|
35
45
|
def other_attrs
|
36
|
-
%i[
|
37
|
-
organisation_name
|
38
|
-
department_name
|
39
|
-
po_box_number
|
40
|
-
post_town
|
41
|
-
postcode
|
42
|
-
udprn
|
43
|
-
]
|
46
|
+
%i[po_box_number udprn]
|
44
47
|
end
|
45
48
|
end
|
46
49
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
class Paf
|
2
|
-
module
|
2
|
+
module CoreExt
|
3
3
|
# Extend the core String class with PAF specific processing
|
4
4
|
module String
|
5
5
|
def paf_exception?
|
@@ -13,4 +13,4 @@ class Paf
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
String.include Paf::
|
16
|
+
String.include Paf::CoreExt::String
|
data/lib/paf/formattable.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'paf/lineable'
|
1
2
|
require 'paf/premises'
|
2
3
|
require 'paf/thoroughfare_locality'
|
3
4
|
|
@@ -7,6 +8,7 @@ class Paf
|
|
7
8
|
def self.included(base)
|
8
9
|
base.extend ClassMethods
|
9
10
|
base.class_eval do
|
11
|
+
include Lineable
|
10
12
|
include Premises
|
11
13
|
include ThoroughfareLocality
|
12
14
|
end
|
@@ -15,16 +17,6 @@ class Paf
|
|
15
17
|
|
16
18
|
# Methods to be added to the including class
|
17
19
|
module ClassMethods
|
18
|
-
def lines_methods
|
19
|
-
%i[
|
20
|
-
organisation_name
|
21
|
-
department_name
|
22
|
-
po_box
|
23
|
-
premises
|
24
|
-
thoroughfares_and_localities
|
25
|
-
]
|
26
|
-
end
|
27
|
-
|
28
20
|
# Formats a hash of PAF address elements into an array of strings
|
29
21
|
def format(args)
|
30
22
|
new(args).format
|
@@ -40,27 +32,16 @@ class Paf
|
|
40
32
|
# Formats a Paf instance into an array of strings
|
41
33
|
def format
|
42
34
|
array = lines
|
43
|
-
|
44
|
-
array << send(attr) unless send(attr).
|
35
|
+
self.class.post_attrs.each do |attr|
|
36
|
+
array << send(attr) unless send(attr).vacant?
|
45
37
|
end
|
46
38
|
array
|
47
39
|
end
|
48
40
|
|
49
41
|
# Formats a Paf instance into a string
|
50
42
|
def to_s
|
51
|
-
string = (lines + [post_town
|
52
|
-
([string] + [postcode]).
|
53
|
-
end
|
54
|
-
|
55
|
-
private
|
56
|
-
|
57
|
-
def lines
|
58
|
-
lines = []
|
59
|
-
self.class.lines_methods.each do |method|
|
60
|
-
value = send(method)
|
61
|
-
(lines << value).flatten! unless value.nil? || value.empty?
|
62
|
-
end
|
63
|
-
lines
|
43
|
+
string = (lines + [post_town]).condense.join(', ')
|
44
|
+
([string] + [postcode]).condense.join('. ')
|
64
45
|
end
|
65
46
|
end
|
66
47
|
end
|
data/lib/paf/lineable.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
class Paf
|
2
|
+
# Processing to format PAF entry lines
|
3
|
+
module Lineable
|
4
|
+
def self.included(base)
|
5
|
+
base.extend ClassMethods
|
6
|
+
end
|
7
|
+
private_class_method :included
|
8
|
+
|
9
|
+
# Methods to be added to the including class
|
10
|
+
module ClassMethods
|
11
|
+
def lines_methods
|
12
|
+
organisation_attrs + %i[po_box premises thoroughfares_and_localities]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def lines
|
19
|
+
lines = []
|
20
|
+
self.class.lines_methods.each do |method|
|
21
|
+
value = send(method)
|
22
|
+
(lines << value).flatten! unless value.vacant?
|
23
|
+
end
|
24
|
+
lines
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/paf/premises.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'paf/premises/string'
|
2
1
|
require 'paf/premises/common'
|
3
2
|
|
4
3
|
class Paf
|
@@ -35,9 +34,7 @@ class Paf
|
|
35
34
|
end
|
36
35
|
|
37
36
|
def rule_key
|
38
|
-
self.class.premises_attrs.map
|
39
|
-
send(attr).to_s.empty? ? 0 : 1
|
40
|
-
end.join
|
37
|
+
self.class.premises_attrs.map { |attr| send(attr).vacant? ? 0 : 1 }.join
|
41
38
|
end
|
42
39
|
end
|
43
40
|
end
|
@@ -20,7 +20,7 @@ class Paf
|
|
20
20
|
self.class.thoroughfare_and_locality_attrs.each do |attr|
|
21
21
|
next if used?(attr)
|
22
22
|
value = send(attr)
|
23
|
-
array << value unless value.
|
23
|
+
array << value unless value.vacant?
|
24
24
|
end
|
25
25
|
array
|
26
26
|
end
|
@@ -32,7 +32,7 @@ class Paf
|
|
32
32
|
|
33
33
|
def first_thoroughfare_or_locality_attr
|
34
34
|
self.class.thoroughfare_and_locality_attrs.find do |attr|
|
35
|
-
!send(attr).
|
35
|
+
!send(attr).vacant?
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
data/lib/paf/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Bard
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -104,7 +104,11 @@ files:
|
|
104
104
|
- bin/setup
|
105
105
|
- lib/paf.rb
|
106
106
|
- lib/paf/attribute.rb
|
107
|
+
- lib/paf/core_ext/array.rb
|
108
|
+
- lib/paf/core_ext/object.rb
|
109
|
+
- lib/paf/core_ext/string.rb
|
107
110
|
- lib/paf/formattable.rb
|
111
|
+
- lib/paf/lineable.rb
|
108
112
|
- lib/paf/premises.rb
|
109
113
|
- lib/paf/premises/common.rb
|
110
114
|
- lib/paf/premises/rule000.rb
|
@@ -114,7 +118,6 @@ files:
|
|
114
118
|
- lib/paf/premises/rule101.rb
|
115
119
|
- lib/paf/premises/rule110.rb
|
116
120
|
- lib/paf/premises/rule111.rb
|
117
|
-
- lib/paf/premises/string.rb
|
118
121
|
- lib/paf/thoroughfare_locality.rb
|
119
122
|
- lib/paf/version.rb
|
120
123
|
- paf.gemspec
|