Class: UKPostcode::GiroPostcode
- Inherits:
-
AbstractPostcode
- Object
- AbstractPostcode
- UKPostcode::GiroPostcode
- Includes:
- Singleton
- Defined in:
- lib/uk_postcode/giro_postcode.rb
Overview
GiroPostcode models the single, peculiar GIR 0AA postcode originally used by Girobank.
area, district, sector, and unit all return nil, because this postcode does not meaningfully possess these distinctions.
Constant Summary collapse
- PATTERN =
/\A G[I1]R \s* [0O]AA \z/ix
Constants inherited from AbstractPostcode
AbstractPostcode::NotImplemented
Class Method Summary collapse
-
.parse(str) ⇒ Object
Returns an instance of GiroPostcode if str represents GIR 0AA, and nil otherwise.
Instance Method Summary collapse
-
#country ⇒ Object
GIR 0AA is in England.
-
#full? ⇒ Boolean
GIR 0AA is always full.
-
#incode ⇒ Object
The right-hand part of the postcode, always “0AA”.
-
#initialize ⇒ GiroPostcode
constructor
A new instance of GiroPostcode.
-
#outcode ⇒ Object
The left-hand part of the postcode, always “GIR”.
-
#to_s ⇒ Object
The canonical string representation of the postcode, i.e.
-
#valid? ⇒ Boolean
GIR 0AA is always valid.
Methods inherited from AbstractPostcode
#area, #district, #full_valid?, #sector, #unit
Constructor Details
#initialize ⇒ GiroPostcode
Returns a new instance of GiroPostcode.
24 25 |
# File 'lib/uk_postcode/giro_postcode.rb', line 24 def initialize end |
Class Method Details
.parse(str) ⇒ Object
Returns an instance of GiroPostcode if str represents GIR 0AA, and nil otherwise.
20 21 22 |
# File 'lib/uk_postcode/giro_postcode.rb', line 20 def self.parse(str) PATTERN.match(str.strip) ? instance : nil end |
Instance Method Details
#country ⇒ Object
GIR 0AA is in England. (In Bootle, in fact.)
59 60 61 |
# File 'lib/uk_postcode/giro_postcode.rb', line 59 def country :england end |
#full? ⇒ Boolean
GIR 0AA is always full.
53 54 55 |
# File 'lib/uk_postcode/giro_postcode.rb', line 53 def full? true end |
#incode ⇒ Object
The right-hand part of the postcode, always “0AA”.
35 36 37 |
# File 'lib/uk_postcode/giro_postcode.rb', line 35 def incode "0AA" end |
#outcode ⇒ Object
The left-hand part of the postcode, always “GIR”.
29 30 31 |
# File 'lib/uk_postcode/giro_postcode.rb', line 29 def outcode "GIR" end |
#to_s ⇒ Object
The canonical string representation of the postcode, i.e. “GIR 0AA”.
41 42 43 |
# File 'lib/uk_postcode/giro_postcode.rb', line 41 def to_s "GIR 0AA" end |
#valid? ⇒ Boolean
GIR 0AA is always valid.
47 48 49 |
# File 'lib/uk_postcode/giro_postcode.rb', line 47 def valid? true end |