paf 0.1.0
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.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.rubocop.yml +4 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +97 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/paf.rb +35 -0
- data/lib/paf/attribute.rb +46 -0
- data/lib/paf/formattable.rb +61 -0
- data/lib/paf/premises.rb +42 -0
- data/lib/paf/premises/common.rb +23 -0
- data/lib/paf/premises/rule000.rb +16 -0
- data/lib/paf/premises/rule001.rb +16 -0
- data/lib/paf/premises/rule010.rb +37 -0
- data/lib/paf/premises/rule011.rb +16 -0
- data/lib/paf/premises/rule101.rb +26 -0
- data/lib/paf/premises/rule110.rb +19 -0
- data/lib/paf/premises/rule111.rb +18 -0
- data/lib/paf/premises/string.rb +16 -0
- data/lib/paf/thoroughfare_locality.rb +43 -0
- data/lib/paf/version.rb +4 -0
- data/paf.gemspec +28 -0
- metadata +141 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a90b60fc8b43ca2ff87c48f4f9f18d4a7e25e3fa
|
4
|
+
data.tar.gz: 2b6baa0e31314fd255162ad545485c21079e68f3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 236d1dbf47af7c6bf6f0e4dc90fb6bd9a4955d932e12e184dea32d01a768eaa900ae04483f295f09f14c24fd20b24c66c29a6694527349d52a8e6abd1f1025e7
|
7
|
+
data.tar.gz: 26a859d3c1085e3722bb2641ca2ce72f0cb2b321747b68a175cacbad188717db4f00a3d3350f82c684df4f36f14e4371fc3788059219cf9b6b5665a67bfed1b6
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at johnbard@globalnet.co.uk. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 John Bard
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
# PAF
|
2
|
+
|
3
|
+
A gem to format the elements of a Royal Mail Postcode Address File entry according to the rules described in the [Royal Mail Programmer's Guide Edition 7, Version 5.0](http://www.royalmail.com/sites/default/files/docs/pdf/programmers_guide_edition_7_v5.pdf)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'paf'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install paf
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
May be used to format the PAF elements as an array of strings:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
Paf.format(
|
27
|
+
building_name: '1-2',
|
28
|
+
thoroughfare_name: 'NURSERY',
|
29
|
+
thoroughfare_descriptor: 'LANE',
|
30
|
+
dependent_locality: 'PENN',
|
31
|
+
post_town: 'HIGH WYCOMBE',
|
32
|
+
postcode: 'HP10 8LS'
|
33
|
+
)
|
34
|
+
|
35
|
+
['1-2 NURSERY LANE', 'PENN', 'HIGH WYCOMBE', 'HP10 8LS']
|
36
|
+
```
|
37
|
+
|
38
|
+
Or as a single string:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
Paf.to_s(
|
42
|
+
building_name: '1-2',
|
43
|
+
thoroughfare_name: 'NURSERY',
|
44
|
+
thoroughfare_descriptor: 'LANE',
|
45
|
+
dependent_locality: 'PENN',
|
46
|
+
post_town: 'HIGH WYCOMBE',
|
47
|
+
postcode: 'HP10 8LS'
|
48
|
+
)
|
49
|
+
|
50
|
+
'1-2 NURSERY LANE, PENN, HIGH WYCOMBE. HP10 8LS'
|
51
|
+
```
|
52
|
+
|
53
|
+
Or from a Paf instance:
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
paf = Paf.new(
|
57
|
+
building_name: '1-2',
|
58
|
+
thoroughfare_name: 'NURSERY',
|
59
|
+
thoroughfare_descriptor: 'LANE',
|
60
|
+
dependent_locality: 'PENN',
|
61
|
+
post_town: 'HIGH WYCOMBE',
|
62
|
+
postcode: 'HP10 8LS'
|
63
|
+
)
|
64
|
+
paf.format
|
65
|
+
|
66
|
+
['1-2 NURSERY LANE', 'PENN', 'HIGH WYCOMBE', 'HP10 8LS']
|
67
|
+
|
68
|
+
paf = Paf.new(
|
69
|
+
building_name: '1-2',
|
70
|
+
thoroughfare_name: 'NURSERY',
|
71
|
+
thoroughfare_descriptor: 'LANE',
|
72
|
+
dependent_locality: 'PENN',
|
73
|
+
post_town: 'HIGH WYCOMBE',
|
74
|
+
postcode: 'HP10 8LS'
|
75
|
+
)
|
76
|
+
paf.to_s
|
77
|
+
|
78
|
+
'1-2 NURSERY LANE, PENN, HIGH WYCOMBE. HP10 8LS'
|
79
|
+
```
|
80
|
+
|
81
|
+
## Development
|
82
|
+
|
83
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
84
|
+
|
85
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
86
|
+
|
87
|
+
## Contributing
|
88
|
+
|
89
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/drabjay/paf. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
90
|
+
|
91
|
+
## License
|
92
|
+
|
93
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
94
|
+
|
95
|
+
## Code of Conduct
|
96
|
+
|
97
|
+
Everyone interacting in the Paf project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/drabjayc/paf/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'paf'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/paf.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'paf/version'
|
2
|
+
require 'paf/attribute'
|
3
|
+
require 'paf/formattable'
|
4
|
+
|
5
|
+
# BCore class from the elements of a UK Royal Mail Postcode Address File entry
|
6
|
+
class Paf
|
7
|
+
include Paf::Attribute
|
8
|
+
include Paf::Formattable
|
9
|
+
|
10
|
+
attr_accessor(*attrs)
|
11
|
+
private(*attrs.map { |attr| "#{attr}=" })
|
12
|
+
|
13
|
+
def initialize(args)
|
14
|
+
args.each { |k, v| send("#{k}=", v) }
|
15
|
+
end
|
16
|
+
|
17
|
+
def po_box
|
18
|
+
"PO BOX #{po_box_number}" unless po_box_number.to_s.empty?
|
19
|
+
end
|
20
|
+
|
21
|
+
def dependent_thoroughfare
|
22
|
+
concatenated(self.class.dependent_thoroughfare_attrs)
|
23
|
+
end
|
24
|
+
|
25
|
+
def thoroughfare
|
26
|
+
concatenated(self.class.thoroughfare_attrs)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def concatenated(attrs)
|
32
|
+
value = attrs.map { |attr| send(attr).to_s }.reject(&:empty?).join(' ')
|
33
|
+
value unless value.to_s.empty?
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
class Paf
|
2
|
+
# Basic attributes that make up a PAF entry
|
3
|
+
module Attribute
|
4
|
+
def self.included(base)
|
5
|
+
base.extend ClassMethods
|
6
|
+
end
|
7
|
+
|
8
|
+
# Methods to be added to the including class
|
9
|
+
module ClassMethods
|
10
|
+
def attrs
|
11
|
+
premises_attrs +
|
12
|
+
dependent_thoroughfare_attrs +
|
13
|
+
thoroughfare_attrs +
|
14
|
+
locality_attrs +
|
15
|
+
other_attrs
|
16
|
+
end
|
17
|
+
|
18
|
+
def premises_attrs
|
19
|
+
%i[sub_building_name building_name building_number]
|
20
|
+
end
|
21
|
+
|
22
|
+
def dependent_thoroughfare_attrs
|
23
|
+
%i[dependent_thoroughfare_name dependent_thoroughfare_descriptor]
|
24
|
+
end
|
25
|
+
|
26
|
+
def thoroughfare_attrs
|
27
|
+
%i[thoroughfare_name thoroughfare_descriptor]
|
28
|
+
end
|
29
|
+
|
30
|
+
def locality_attrs
|
31
|
+
%i[double_dependent_locality dependent_locality]
|
32
|
+
end
|
33
|
+
|
34
|
+
def other_attrs
|
35
|
+
%i[
|
36
|
+
organisation_name
|
37
|
+
department_name
|
38
|
+
po_box_number
|
39
|
+
post_town
|
40
|
+
postcode
|
41
|
+
udprn
|
42
|
+
]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'paf/premises'
|
2
|
+
require 'paf/thoroughfare_locality'
|
3
|
+
|
4
|
+
class Paf
|
5
|
+
# Processing to format a PAF entry
|
6
|
+
module Formattable
|
7
|
+
def self.included(base)
|
8
|
+
base.extend ClassMethods
|
9
|
+
base.class_eval do
|
10
|
+
include Premises
|
11
|
+
include ThoroughfareLocality
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Methods to be added to the including class
|
16
|
+
module ClassMethods
|
17
|
+
def lines_methods
|
18
|
+
%i[
|
19
|
+
organisation_name
|
20
|
+
department_name
|
21
|
+
po_box
|
22
|
+
premises
|
23
|
+
thoroughfares_and_localities
|
24
|
+
]
|
25
|
+
end
|
26
|
+
|
27
|
+
def format(args)
|
28
|
+
new(args).format
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_s(*args)
|
32
|
+
return super if args.empty?
|
33
|
+
new(args[0]).to_s
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def format
|
38
|
+
array = lines
|
39
|
+
%i[post_town postcode].each do |attr|
|
40
|
+
array << send(attr) unless send(attr).to_s.empty?
|
41
|
+
end
|
42
|
+
array
|
43
|
+
end
|
44
|
+
|
45
|
+
def to_s
|
46
|
+
string = (lines + [post_town.to_s]).reject(&:empty?).join(', ')
|
47
|
+
([string] + [postcode]).reject(&:empty?).join('. ')
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def lines
|
53
|
+
lines = []
|
54
|
+
self.class.lines_methods.each do |method|
|
55
|
+
value = send(method)
|
56
|
+
(lines << value).flatten! unless value.nil? || value.empty?
|
57
|
+
end
|
58
|
+
lines
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/paf/premises.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'paf/premises/string'
|
2
|
+
require 'paf/premises/common'
|
3
|
+
|
4
|
+
class Paf
|
5
|
+
# Determine which premises rule is applicable
|
6
|
+
module Premises
|
7
|
+
include Common
|
8
|
+
|
9
|
+
def self.included(base)
|
10
|
+
base.prepend Initializer
|
11
|
+
end
|
12
|
+
|
13
|
+
# initialize method to be prepended to the including class
|
14
|
+
module Initializer
|
15
|
+
def initialize(*)
|
16
|
+
super if defined? super
|
17
|
+
extend_premises_rule
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def extend_premises_rule
|
24
|
+
require premises_rule_filename
|
25
|
+
extend premises_rule_module
|
26
|
+
end
|
27
|
+
|
28
|
+
def premises_rule_filename
|
29
|
+
"paf/premises/rule#{rule_key}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def premises_rule_module
|
33
|
+
Kernel.const_get("Paf::Premises::Rule#{rule_key}")
|
34
|
+
end
|
35
|
+
|
36
|
+
def rule_key
|
37
|
+
self.class.premises_attrs.map do |attr|
|
38
|
+
send(attr).to_s.empty? ? 0 : 1
|
39
|
+
end.join
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Paf
|
2
|
+
module Premises
|
3
|
+
# Common processing for premises elements of a PAF entry
|
4
|
+
module Common
|
5
|
+
attr_accessor :concatenation_indicator
|
6
|
+
private :concatenation_indicator=
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def sub_name_and_name
|
11
|
+
"#{sub_building_name} #{building_name}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def number_and_thoroughfare_or_locality
|
15
|
+
"#{building_number} #{first_thoroughfare_or_locality}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def name_and_thoroughfare_or_locality
|
19
|
+
"#{building_name} #{first_thoroughfare_or_locality}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Paf
|
2
|
+
module Premises
|
3
|
+
# Processing for premises elements of a PAF entry under Rule 2
|
4
|
+
module Rule001
|
5
|
+
private
|
6
|
+
|
7
|
+
def premises
|
8
|
+
[number_and_thoroughfare_or_locality]
|
9
|
+
end
|
10
|
+
|
11
|
+
def premises_includes_first_thoroughfare_or_locality?
|
12
|
+
true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class Paf
|
2
|
+
module Premises
|
3
|
+
# Processing for premises elements of a PAF entry under Rule 3
|
4
|
+
module Rule010
|
5
|
+
private
|
6
|
+
|
7
|
+
def premises
|
8
|
+
return [name_and_thoroughfare_or_locality] if
|
9
|
+
building_name.paf_exception?
|
10
|
+
if building_name_last_word.paf_split_exception?
|
11
|
+
return [
|
12
|
+
building_name_but_last_word,
|
13
|
+
name_last_word_and_thoroughfare_or_locality
|
14
|
+
]
|
15
|
+
end
|
16
|
+
[building_name]
|
17
|
+
end
|
18
|
+
|
19
|
+
def premises_includes_first_thoroughfare_or_locality?
|
20
|
+
building_name.paf_exception? ||
|
21
|
+
building_name_last_word.paf_split_exception?
|
22
|
+
end
|
23
|
+
|
24
|
+
def building_name_but_last_word
|
25
|
+
building_name[0...building_name.rindex(' ')]
|
26
|
+
end
|
27
|
+
|
28
|
+
def building_name_last_word
|
29
|
+
building_name.split.last
|
30
|
+
end
|
31
|
+
|
32
|
+
def name_last_word_and_thoroughfare_or_locality
|
33
|
+
"#{building_name_last_word} #{first_thoroughfare_or_locality}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Paf
|
2
|
+
module Premises
|
3
|
+
# Processing for premises elements of a PAF entry under Rule 4
|
4
|
+
module Rule011
|
5
|
+
private
|
6
|
+
|
7
|
+
def premises
|
8
|
+
[building_name, number_and_thoroughfare_or_locality]
|
9
|
+
end
|
10
|
+
|
11
|
+
def premises_includes_first_thoroughfare_or_locality?
|
12
|
+
true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class Paf
|
2
|
+
module Premises
|
3
|
+
# Processing for premises elements of a PAF entry under Rule 5
|
4
|
+
module Rule101
|
5
|
+
private
|
6
|
+
|
7
|
+
def premises
|
8
|
+
return [number_sub_name_and_thoroughfare_or_locality] if concatenate?
|
9
|
+
[sub_building_name, number_and_thoroughfare_or_locality]
|
10
|
+
end
|
11
|
+
|
12
|
+
def premises_includes_first_thoroughfare_or_locality?
|
13
|
+
true
|
14
|
+
end
|
15
|
+
|
16
|
+
def concatenate?
|
17
|
+
concatenation_indicator == 'Y'
|
18
|
+
end
|
19
|
+
|
20
|
+
def number_sub_name_and_thoroughfare_or_locality
|
21
|
+
"#{building_number}#{sub_building_name} "\
|
22
|
+
"#{first_thoroughfare_or_locality}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class Paf
|
2
|
+
module Premises
|
3
|
+
# Processing for premises elements of a PAF entry under Rule 6
|
4
|
+
module Rule110
|
5
|
+
private
|
6
|
+
|
7
|
+
def premises
|
8
|
+
return [sub_name_and_name] if sub_building_name.paf_exception?
|
9
|
+
return [sub_building_name, name_and_thoroughfare_or_locality] if
|
10
|
+
building_name.paf_exception?
|
11
|
+
[sub_building_name, building_name]
|
12
|
+
end
|
13
|
+
|
14
|
+
def premises_includes_first_thoroughfare_or_locality?
|
15
|
+
!sub_building_name.paf_exception? && building_name.paf_exception?
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class Paf
|
2
|
+
module Premises
|
3
|
+
# Processing for premises elements of a PAF entry under Rule 7
|
4
|
+
module Rule111
|
5
|
+
private
|
6
|
+
|
7
|
+
def premises
|
8
|
+
return [sub_name_and_name, number_and_thoroughfare_or_locality] if
|
9
|
+
sub_building_name.paf_exception?
|
10
|
+
[sub_building_name, building_name, number_and_thoroughfare_or_locality]
|
11
|
+
end
|
12
|
+
|
13
|
+
def premises_includes_first_thoroughfare_or_locality?
|
14
|
+
true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Paf
|
2
|
+
module Premises
|
3
|
+
# Extend the core String class with PAF specific processing
|
4
|
+
module String
|
5
|
+
def paf_exception?
|
6
|
+
!/^(.|[\d][[:alpha:]]|[\d].*?[\d][[:alpha:]]?)$/.match(self).nil?
|
7
|
+
end
|
8
|
+
|
9
|
+
def paf_split_exception?
|
10
|
+
paf_exception? && /^\d+$/.match(self).nil?
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
String.include Paf::Premises::String
|
@@ -0,0 +1,43 @@
|
|
1
|
+
class Paf
|
2
|
+
# Processing for thoroughfare and locality elements of a PAF entry
|
3
|
+
module ThoroughfareLocality
|
4
|
+
def self.included(base)
|
5
|
+
base.extend ClassMethods
|
6
|
+
end
|
7
|
+
|
8
|
+
# Methods to be added to the including class
|
9
|
+
module ClassMethods
|
10
|
+
def thoroughfare_and_locality_attrs
|
11
|
+
%i[dependent_thoroughfare thoroughfare] + locality_attrs
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def thoroughfares_and_localities
|
18
|
+
array = []
|
19
|
+
self.class.thoroughfare_and_locality_attrs.each do |attr|
|
20
|
+
next if used?(attr)
|
21
|
+
value = send(attr)
|
22
|
+
array << value unless value.to_s.empty?
|
23
|
+
end
|
24
|
+
array
|
25
|
+
end
|
26
|
+
|
27
|
+
def first_thoroughfare_or_locality
|
28
|
+
send(first_thoroughfare_or_locality_attr) unless
|
29
|
+
first_thoroughfare_or_locality_attr.nil?
|
30
|
+
end
|
31
|
+
|
32
|
+
def first_thoroughfare_or_locality_attr
|
33
|
+
self.class.thoroughfare_and_locality_attrs.find do |attr|
|
34
|
+
!send(attr).to_s.empty?
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def used?(attr)
|
39
|
+
premises_includes_first_thoroughfare_or_locality? &&
|
40
|
+
(attr == first_thoroughfare_or_locality_attr)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/paf/version.rb
ADDED
data/paf.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'paf/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'paf'
|
9
|
+
spec.version = Paf::VERSION
|
10
|
+
spec.authors = ['John Bard']
|
11
|
+
spec.email = ['johnbard@globalnet.co.uk']
|
12
|
+
|
13
|
+
spec.summary = 'Royal Mail PAF Formatter'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = 'exe'
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.15'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.5'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.6'
|
26
|
+
spec.add_development_dependency 'rubocop', '~> 0.49'
|
27
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 1.4'
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: paf
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Bard
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-06-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.49'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.49'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop-rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.4'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.4'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- johnbard@globalnet.co.uk
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".rubocop.yml"
|
93
|
+
- ".travis.yml"
|
94
|
+
- CODE_OF_CONDUCT.md
|
95
|
+
- Gemfile
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- bin/console
|
100
|
+
- bin/setup
|
101
|
+
- lib/paf.rb
|
102
|
+
- lib/paf/attribute.rb
|
103
|
+
- lib/paf/formattable.rb
|
104
|
+
- lib/paf/premises.rb
|
105
|
+
- lib/paf/premises/common.rb
|
106
|
+
- lib/paf/premises/rule000.rb
|
107
|
+
- lib/paf/premises/rule001.rb
|
108
|
+
- lib/paf/premises/rule010.rb
|
109
|
+
- lib/paf/premises/rule011.rb
|
110
|
+
- lib/paf/premises/rule101.rb
|
111
|
+
- lib/paf/premises/rule110.rb
|
112
|
+
- lib/paf/premises/rule111.rb
|
113
|
+
- lib/paf/premises/string.rb
|
114
|
+
- lib/paf/thoroughfare_locality.rb
|
115
|
+
- lib/paf/version.rb
|
116
|
+
- paf.gemspec
|
117
|
+
homepage:
|
118
|
+
licenses:
|
119
|
+
- MIT
|
120
|
+
metadata: {}
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
requirements: []
|
136
|
+
rubyforge_project:
|
137
|
+
rubygems_version: 2.5.2
|
138
|
+
signing_key:
|
139
|
+
specification_version: 4
|
140
|
+
summary: Royal Mail PAF Formatter
|
141
|
+
test_files: []
|