Class: UKPostcode::InvalidPostcode

Inherits:
AbstractPostcode show all
Defined in:
lib/uk_postcode/invalid_postcode.rb

Overview

An InvalidPostcode is returned by UKPostcode.parse when it is unable to parse the supplied postcode. As it returns the input verbatim via #to_s, it’s possible to do UKPostcode.parse(s).to_s and get either a normalised postcode (if possible) or the original user input.

The sub-fields of the postcode (outcode, area, etc.) are all nil.

Constant Summary

Constants inherited from AbstractPostcode

AbstractPostcode::NotImplemented

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractPostcode

#area, #country, #district, #full_valid?, #incode, #outcode, #sector, #unit

Constructor Details

#initialize(input) ⇒ InvalidPostcode

Returns a new instance of InvalidPostcode.



17
18
19
# File 'lib/uk_postcode/invalid_postcode.rb', line 17

def initialize(input)
  @input = input
end

Class Method Details

.parse(str) ⇒ Object



13
14
15
# File 'lib/uk_postcode/invalid_postcode.rb', line 13

def self.parse(str)
  new(str)
end

Instance Method Details

#full?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/uk_postcode/invalid_postcode.rb', line 28

def full?
  false
end

#to_sObject

Returns the literal string supplied at initialisation. This may be helpful when returning erroneous input to the user.



24
25
26
# File 'lib/uk_postcode/invalid_postcode.rb', line 24

def to_s
  @input
end

#valid?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/uk_postcode/invalid_postcode.rb', line 32

def valid?
  false
end