paf 0.4.0 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b233ff56fedadfea9e1f21508ea7b6fb85f852c1
4
- data.tar.gz: 59dbbde56e750c387774368cad006e4d3e4a0a7c
2
+ SHA256:
3
+ metadata.gz: ff95e5cecbf89542069a082cc4267ce172f9a3c8e31658ec62d6603ef57e2ca7
4
+ data.tar.gz: 441db96e17ce9102520fb810e5900d6d0be89959b6428e2a336c14ba569fa7d8
5
5
  SHA512:
6
- metadata.gz: c379a989578aa2c9a0398f26dddf50d0cce40d15f0ddc8394e54e24bd7c13c016b30734ff3f2375ff985d63caf707d9b024c8720edade1ac3cccbf7a67b78779
7
- data.tar.gz: 7414a214e0a027bffa8c774f595844a208e75db227af5f2338e9e2f80804088f0e50a0ff39c69f2a5e01412582060d39faa36badd96365ebf630abc8a4a18579
6
+ metadata.gz: '029f8dedc38e173e6ca65ea1d66fd39d2ed306d3292e9a2b86d5ec49f79bc47b56b91753885cd98d7f51dd64f6e758517df046eb0d7068ed6cb618e55157cdda'
7
+ data.tar.gz: b93b2170bc646954ebcd14eaabf11e5e7b467432cad4111f93b294cb71bc307149dd0d93d07cdcbe9be42bbd66b519574de7dfa252e52f010fe4cf54b6d29eb9
data/.rubocop.yml CHANGED
@@ -1,4 +1,13 @@
1
1
  require: rubocop-rspec
2
2
 
3
+ AllCops:
4
+ TargetRubyVersion: 2.4
5
+
3
6
  RSpec/ExampleLength:
4
- Max: 25
7
+ Max: 25
8
+
9
+ Style/EndOfLine:
10
+ EnforcedStyle: lf
11
+
12
+ Style/FrozenStringLiteralComment:
13
+ Enabled: false
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # PAF
2
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)
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 6.2](https://www.poweredbypaf.com/wp-content/uploads/2024/11/Latest-Programmers_guide_Edition-7-Version-6-2.pdf)
4
4
 
5
5
  ## Installation
6
6
 
@@ -20,10 +20,10 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- May be used to format the PAF elements as an array of strings:
23
+ May be used to format the Paf::Address elements as an array of strings:
24
24
 
25
25
  ```ruby
26
- Paf.to_a(
26
+ Paf::Address.to_a(
27
27
  building_name: '1-2',
28
28
  thoroughfare_name: 'NURSERY',
29
29
  thoroughfare_descriptor: 'LANE',
@@ -38,7 +38,7 @@ Paf.to_a(
38
38
  Or as a hash of strings:
39
39
 
40
40
  ```ruby
41
- Paf.to_h(
41
+ Paf::Address.to_h(
42
42
  building_name: '1-2',
43
43
  thoroughfare_name: 'NURSERY',
44
44
  thoroughfare_descriptor: 'LANE',
@@ -57,7 +57,7 @@ Paf.to_h(
57
57
  Or as a single string:
58
58
 
59
59
  ```ruby
60
- Paf.to_s(
60
+ Paf::Address.to_s(
61
61
  building_name: '1-2',
62
62
  thoroughfare_name: 'NURSERY',
63
63
  thoroughfare_descriptor: 'LANE',
@@ -69,10 +69,10 @@ Paf.to_s(
69
69
  '1-2 NURSERY LANE, PENN, HIGH WYCOMBE. HP10 8LS'
70
70
  ```
71
71
 
72
- Or from a Paf instance:
72
+ Or from a Paf::Address instance:
73
73
 
74
74
  ```ruby
75
- paf = Paf.new(
75
+ address = Paf::Address.new(
76
76
  building_name: '1-2',
77
77
  thoroughfare_name: 'NURSERY',
78
78
  thoroughfare_descriptor: 'LANE',
@@ -80,11 +80,11 @@ paf = Paf.new(
80
80
  post_town: 'HIGH WYCOMBE',
81
81
  postcode: 'HP10 8LS'
82
82
  )
83
- paf.to_a
83
+ address.to_a
84
84
 
85
85
  ['1-2 NURSERY LANE', 'PENN', 'HIGH WYCOMBE', 'HP10 8LS']
86
86
 
87
- paf = Paf.new(
87
+ address = Paf::Address.new(
88
88
  building_name: '1-2',
89
89
  thoroughfare_name: 'NURSERY',
90
90
  thoroughfare_descriptor: 'LANE',
@@ -92,7 +92,7 @@ paf = Paf.new(
92
92
  post_town: 'HIGH WYCOMBE',
93
93
  postcode: 'HP10 8LS'
94
94
  )
95
- paf.to_h
95
+ address.to_h
96
96
 
97
97
  {
98
98
  lines: ['1-2 NURSERY LANE', 'PENN'],
@@ -100,7 +100,7 @@ paf.to_h
100
100
  postcode: 'HP10 8LS'
101
101
  }
102
102
 
103
- paf = Paf.new(
103
+ address = Paf::Address.new(
104
104
  building_name: '1-2',
105
105
  thoroughfare_name: 'NURSERY',
106
106
  thoroughfare_descriptor: 'LANE',
@@ -108,7 +108,7 @@ paf = Paf.new(
108
108
  post_town: 'HIGH WYCOMBE',
109
109
  postcode: 'HP10 8LS'
110
110
  )
111
- paf.to_s
111
+ address.to_s
112
112
 
113
113
  '1-2 NURSERY LANE, PENN, HIGH WYCOMBE. HP10 8LS'
114
114
  ```
@@ -0,0 +1,39 @@
1
+ require 'paf/attribute'
2
+ require 'paf/formattable'
3
+
4
+ module Paf
5
+ # Base class from the elements of a UK Royal Mail Postcode Address File entry
6
+ class Address
7
+ include Paf::Attribute
8
+ include Paf::Formattable
9
+
10
+ attr_accessor(*attrs)
11
+ private(*attrs.map { |attr| "#{attr}=" }) # rubocop:disable Style/AccessModifierDeclarations
12
+
13
+ def initialize(args)
14
+ args.each { |k, v| send("#{k}=", v) }
15
+ end
16
+
17
+ # PO Box number prepended with the string PO BOX
18
+ def po_box
19
+ "PO BOX #{po_box_number}" unless po_box_number.vacant?
20
+ end
21
+
22
+ # Dependent thoroughfare name and descriptor
23
+ def dependent_thoroughfare
24
+ concatenated(self.class.dependent_thoroughfare_attrs)
25
+ end
26
+
27
+ # Thoroughfare name and descriptor
28
+ def thoroughfare
29
+ concatenated(self.class.thoroughfare_attrs)
30
+ end
31
+
32
+ private
33
+
34
+ def concatenated(attrs)
35
+ value = attrs.map { |attr| send(attr) }.condense(' ')
36
+ value unless value.vacant?
37
+ end
38
+ end
39
+ end
@@ -1,6 +1,6 @@
1
1
  require 'paf/formatter'
2
2
 
3
- class Paf
3
+ module Paf
4
4
  # Processing to format a PAF entry as an array
5
5
  class ArrayFormatter < Formatter
6
6
  def format(paf)
data/lib/paf/attribute.rb CHANGED
@@ -1,4 +1,4 @@
1
- class Paf
1
+ module Paf
2
2
  # Basic attributes or elements that make up a PAF entry
3
3
  module Attribute
4
4
  def self.included(base)
@@ -1,6 +1,6 @@
1
1
  require 'paf/core_ext/string'
2
2
 
3
- class Paf
3
+ module Paf
4
4
  module CoreExt
5
5
  # Extend the core Array class with PAF specific processing
6
6
  module Array
@@ -1,4 +1,4 @@
1
- class Paf
1
+ module Paf
2
2
  module CoreExt
3
3
  # Extend the core Object class with PAF specific processing
4
4
  module Object
@@ -1,4 +1,4 @@
1
- class Paf
1
+ module Paf
2
2
  module CoreExt
3
3
  # Extend the core String class with PAF specific processing
4
4
  module String
@@ -7,7 +7,7 @@ class Paf
7
7
  end
8
8
 
9
9
  def split_exception?
10
- last_word.exception? && /^\d+$/.match(last_word).nil?
10
+ last_word.exception? && /^\d+$/.match(last_word).nil? && !but_last_word.known_building_type?
11
11
  end
12
12
 
13
13
  def last_word
@@ -17,6 +17,13 @@ class Paf
17
17
  def but_last_word
18
18
  self[0...rindex(' ')]
19
19
  end
20
+
21
+ def known_building_type?
22
+ [
23
+ 'BACK OF', 'BLOCK', 'BLOCKS', 'BUILDING', 'MAISONETTE', 'MAISONETTES', 'REAR OF',
24
+ 'SHOP', 'SHOPS', 'STALL', 'STALLS', 'SUITE', 'SUITES', 'UNIT', 'UNITS'
25
+ ].include?(self)
26
+ end
20
27
  end
21
28
  end
22
29
  end
@@ -2,7 +2,7 @@ require 'paf/array_formatter'
2
2
  require 'paf/hash_formatter'
3
3
  require 'paf/string_formatter'
4
4
 
5
- class Paf
5
+ module Paf
6
6
  # Processing to format a PAF entry
7
7
  module Formattable
8
8
  attr_accessor :formatter, :concatenation_indicator
@@ -32,6 +32,7 @@ class Paf
32
32
 
33
33
  def to_s(*args)
34
34
  return super if args.empty?
35
+
35
36
  new(args[0]).to_s
36
37
  end
37
38
  end
data/lib/paf/formatter.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'paf/lineable'
2
2
 
3
- class Paf
3
+ module Paf
4
4
  # Processing to format a PAF entry
5
5
  class Formatter
6
6
  def self.format(paf)
@@ -15,6 +15,7 @@ class Paf
15
15
  def method_missing(method, *args)
16
16
  return @paf.send(method, *args) if @paf.respond_to?(method)
17
17
  return @paf.class.send(method, *args) if @paf.class.respond_to?(method)
18
+
18
19
  super
19
20
  end
20
21
 
@@ -1,6 +1,6 @@
1
1
  require 'paf/formatter'
2
2
 
3
- class Paf
3
+ module Paf
4
4
  # Processing to format a PAF entry as a hash
5
5
  class HashFormatter < Formatter
6
6
  def format(paf)
data/lib/paf/lineable.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'paf/premises'
2
2
  require 'paf/thoroughfare_locality'
3
3
 
4
- class Paf
4
+ module Paf
5
5
  # Processing to format PAF entry lines
6
6
  module Lineable
7
7
  def self.extended(base)
@@ -12,8 +12,7 @@ class Paf
12
12
  def lines
13
13
  [].tap do |lines|
14
14
  lines_methods.each do |method|
15
- value = send(method)
16
- (lines << value).flatten! unless value.vacant?
15
+ (lines << send(method)).flatten! unless send(method).vacant?
17
16
  end
18
17
  end
19
18
  end
@@ -1,4 +1,4 @@
1
- class Paf
1
+ module Paf
2
2
  module Premises
3
3
  # Common processing for premises elements of a PAF entry
4
4
  module Common
@@ -1,4 +1,4 @@
1
- class Paf
1
+ module Paf
2
2
  module Premises
3
3
  # Processing for premises elements of a PAF entry under Rule 1
4
4
  module Rule000
@@ -1,4 +1,4 @@
1
- class Paf
1
+ module Paf
2
2
  module Premises
3
3
  # Processing for premises elements of a PAF entry under Rule 2
4
4
  module Rule001
@@ -1,9 +1,10 @@
1
- class Paf
1
+ module Paf
2
2
  module Premises
3
3
  # Processing for premises elements of a PAF entry under Rule 3
4
4
  module Rule010
5
5
  def premises
6
6
  return [name_and_thoroughfare_or_locality] if building_name.exception?
7
+
7
8
  if building_name.split_exception?
8
9
  return [
9
10
  building_name.but_last_word,
@@ -1,4 +1,4 @@
1
- class Paf
1
+ module Paf
2
2
  module Premises
3
3
  # Processing for premises elements of a PAF entry under Rule 4
4
4
  module Rule011
@@ -1,9 +1,10 @@
1
- class Paf
1
+ module Paf
2
2
  module Premises
3
3
  # Processing for premises elements of a PAF entry under Rule 5
4
4
  module Rule101
5
5
  def premises
6
6
  return [number_sub_name_and_thoroughfare_or_locality] if concatenate?
7
+
7
8
  [sub_building_name, number_and_thoroughfare_or_locality]
8
9
  end
9
10
 
@@ -1,4 +1,4 @@
1
- class Paf
1
+ module Paf
2
2
  module Premises
3
3
  # Processing for premises elements of a PAF entry under Rule 6
4
4
  module Rule110
@@ -6,6 +6,7 @@ class Paf
6
6
  return [sub_name_and_name] if sub_building_name.exception?
7
7
  return [sub_building_name, name_and_thoroughfare_or_locality] if
8
8
  building_name.exception?
9
+
9
10
  [sub_building_name, building_name]
10
11
  end
11
12
 
@@ -1,17 +1,23 @@
1
- class Paf
1
+ module Paf
2
2
  module Premises
3
3
  # Processing for premises elements of a PAF entry under Rule 7
4
4
  module Rule111
5
5
  def premises
6
+ return [sub_name_comma_name] if building_number.zero?
6
7
  return [sub_name_and_name, number_and_thoroughfare_or_locality] if
7
8
  sub_building_name.exception?
9
+
8
10
  [sub_building_name, building_name, number_and_thoroughfare_or_locality]
9
11
  end
10
12
 
11
13
  private
12
14
 
13
15
  def premises_includes_first_thoroughfare_or_locality?
14
- true
16
+ !building_number.zero?
17
+ end
18
+
19
+ def sub_name_comma_name
20
+ "#{sub_building_name}, #{building_name}"
15
21
  end
16
22
  end
17
23
  end
data/lib/paf/premises.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'paf/premises/common'
2
2
 
3
- class Paf
3
+ module Paf
4
4
  # Determine which premises rule is applicable
5
5
  module Premises
6
6
  include Common
@@ -1,6 +1,6 @@
1
1
  require 'paf/formatter'
2
2
 
3
- class Paf
3
+ module Paf
4
4
  # Processing to format a PAF entry as a string
5
5
  class StringFormatter < Formatter
6
6
  def format(paf)
@@ -1,36 +1,36 @@
1
- class Paf
1
+ module Paf
2
2
  # Processing for thoroughfare and locality elements of a PAF entry
3
3
  module ThoroughfareLocality
4
- def thoroughfare_and_locality_attrs
5
- %i[dependent_thoroughfare thoroughfare] + self.class.locality_attrs
6
- end
7
-
8
4
  def thoroughfares_and_localities
9
5
  [].tap do |array|
10
6
  thoroughfare_and_locality_attrs.each do |attr|
11
- next if used?(attr)
12
- value = send(attr)
13
- array << value unless value.vacant?
7
+ array << send(attr) unless used_or_vacant?(attr)
14
8
  end
15
9
  end
16
10
  end
17
11
 
18
12
  private
19
13
 
14
+ def thoroughfare_and_locality_attrs
15
+ %i[dependent_thoroughfare thoroughfare] + self.class.locality_attrs
16
+ end
17
+
20
18
  def first_thoroughfare_or_locality
21
19
  send(first_thoroughfare_or_locality_attr) unless
22
20
  first_thoroughfare_or_locality_attr.nil?
23
21
  end
24
22
 
25
23
  def first_thoroughfare_or_locality_attr
26
- thoroughfare_and_locality_attrs.find do |attr|
27
- !send(attr).vacant?
28
- end
24
+ thoroughfare_and_locality_attrs.find { |attr| !send(attr).vacant? }
29
25
  end
30
26
 
31
27
  def used?(attr)
32
28
  premises_includes_first_thoroughfare_or_locality? &&
33
29
  (attr == first_thoroughfare_or_locality_attr)
34
30
  end
31
+
32
+ def used_or_vacant?(attr)
33
+ used?(attr) || send(attr).vacant?
34
+ end
35
35
  end
36
36
  end
data/lib/paf/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # PAF gem version
2
- class Paf
3
- VERSION = '0.4.0'.freeze
2
+ module Paf
3
+ VERSION = '0.6.0'.freeze
4
4
  end
data/lib/paf.rb CHANGED
@@ -1,41 +1,9 @@
1
1
  require 'paf/version'
2
- require 'paf/attribute'
3
- require 'paf/formattable'
2
+ require 'paf/address'
4
3
  require 'paf/core_ext/object'
5
4
  require 'paf/core_ext/string'
6
5
  require 'paf/core_ext/array'
7
6
 
8
- # Base class from the elements of a UK Royal Mail Postcode Address File entry
9
- class Paf
10
- include Paf::Attribute
11
- include Paf::Formattable
12
-
13
- attr_accessor(*attrs)
14
- private(*attrs.map { |attr| "#{attr}=" })
15
-
16
- def initialize(args)
17
- args.each { |k, v| send("#{k}=", v) }
18
- end
19
-
20
- # PO Box number prepended with the string PO BOX
21
- def po_box
22
- "PO BOX #{po_box_number}" unless po_box_number.vacant?
23
- end
24
-
25
- # Dependent thoroughfare name and descriptor
26
- def dependent_thoroughfare
27
- concatenated(self.class.dependent_thoroughfare_attrs)
28
- end
29
-
30
- # Thoroughfare name and descriptor
31
- def thoroughfare
32
- concatenated(self.class.thoroughfare_attrs)
33
- end
34
-
35
- private
36
-
37
- def concatenated(attrs)
38
- value = attrs.map { |attr| send(attr) }.condense(' ')
39
- value unless value.vacant?
40
- end
7
+ # Base module for UK Royal Mail Postcode Address File processing
8
+ module Paf
41
9
  end
data/paf.gemspec CHANGED
@@ -1,6 +1,4 @@
1
- # coding: utf-8
2
-
3
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
4
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
3
  require 'paf/version'
6
4
 
@@ -12,12 +10,12 @@ Gem::Specification.new do |spec|
12
10
  spec.homepage = 'https://github.com/drabjay/paf'
13
11
 
14
12
  spec.summary = 'Royal Mail Postcode Address File (PAF) Formatter'
15
- spec.description = <<-EOF
13
+ spec.description = <<-DESC
16
14
  A gem to format the elements of a Royal Mail Postcode Address File entry
17
15
  according to the rules described in the Royal Mail Programmer's Guide
18
- Edition 7, Version 5.0
19
- (http://www.royalmail.com/sites/default/files/docs/pdf/programmers_guide_edition_7_v5.pdf)
20
- EOF
16
+ Edition 7, Version 6.2
17
+ (https://www.poweredbypaf.com/wp-content/uploads/2024/11/Latest-Programmers_guide_Edition-7-Version-6-2.pdf)
18
+ DESC
21
19
  spec.license = 'MIT'
22
20
 
23
21
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
@@ -27,6 +25,7 @@ Gem::Specification.new do |spec|
27
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
26
  spec.require_paths = ['lib']
29
27
 
28
+ spec.required_ruby_version = '>= 2.4'
30
29
  spec.add_development_dependency 'bundler', '~> 1.15'
31
30
  spec.add_development_dependency 'rake', '~> 10.5'
32
31
  spec.add_development_dependency 'rspec', '~> 3.6'
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.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Bard
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-07-08 00:00:00.000000000 Z
11
+ date: 2025-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -83,8 +83,8 @@ dependencies:
83
83
  description: |2
84
84
  A gem to format the elements of a Royal Mail Postcode Address File entry
85
85
  according to the rules described in the Royal Mail Programmer's Guide
86
- Edition 7, Version 5.0
87
- (http://www.royalmail.com/sites/default/files/docs/pdf/programmers_guide_edition_7_v5.pdf)
86
+ Edition 7, Version 6.2
87
+ (https://www.poweredbypaf.com/wp-content/uploads/2024/11/Latest-Programmers_guide_Edition-7-Version-6-2.pdf)
88
88
  email:
89
89
  - johnbard@globalnet.co.uk
90
90
  executables: []
@@ -103,6 +103,7 @@ files:
103
103
  - bin/console
104
104
  - bin/setup
105
105
  - lib/paf.rb
106
+ - lib/paf/address.rb
106
107
  - lib/paf/array_formatter.rb
107
108
  - lib/paf/attribute.rb
108
109
  - lib/paf/core_ext/array.rb
@@ -129,7 +130,7 @@ homepage: https://github.com/drabjay/paf
129
130
  licenses:
130
131
  - MIT
131
132
  metadata: {}
132
- post_install_message:
133
+ post_install_message:
133
134
  rdoc_options: []
134
135
  require_paths:
135
136
  - lib
@@ -137,16 +138,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
137
138
  requirements:
138
139
  - - ">="
139
140
  - !ruby/object:Gem::Version
140
- version: '0'
141
+ version: '2.4'
141
142
  required_rubygems_version: !ruby/object:Gem::Requirement
142
143
  requirements:
143
144
  - - ">="
144
145
  - !ruby/object:Gem::Version
145
146
  version: '0'
146
147
  requirements: []
147
- rubyforge_project:
148
- rubygems_version: 2.5.2
149
- signing_key:
148
+ rubygems_version: 3.0.3
149
+ signing_key:
150
150
  specification_version: 4
151
151
  summary: Royal Mail Postcode Address File (PAF) Formatter
152
152
  test_files: []