Class: UKPostcode::GiroPostcode

Inherits:
AbstractPostcode show all
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

Instance Method Summary collapse

Methods inherited from AbstractPostcode

#area, #district, #full_valid?, #sector, #unit

Constructor Details

#initializeGiroPostcode

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

#countryObject

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.

Returns:

  • (Boolean)


53
54
55
# File 'lib/uk_postcode/giro_postcode.rb', line 53

def full?
  true
end

#incodeObject

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

#outcodeObject

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_sObject

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.

Returns:

  • (Boolean)


47
48
49
# File 'lib/uk_postcode/giro_postcode.rb', line 47

def valid?
  true
end