class Regional::Postcode
Canadian postal code
Public Class Methods
new(string)
click to toggle source
returns ‘nil` if string is not a postal code
# File lib/regional/postcode.rb, line 8 def initialize(string) string = string.scan(/[a-z0-9]+/i).join.upcase string = string.match(@@pattern).to_s raise FormatDoesntMatch if string.empty? @fsa = string[0..2] @ldu = string[3..5] end
Public Instance Methods
illegal_characters?()
click to toggle source
# File lib/regional/postcode.rb, line 33 def illegal_characters? to_s =~ /[DFIOQUW]/ end
inspect()
click to toggle source
# File lib/regional/postcode.rb, line 37 def inspect "#<#{self.class.name} #{to_s}>" end
pp()
click to toggle source
# File lib/regional/postcode.rb, line 21 def pp @fsa + ' ' + @ldu end
squeeze()
click to toggle source
# File lib/regional/postcode.rb, line 25 def squeeze @fsa + @ldu end
to_s()
click to toggle source
# File lib/regional/postcode.rb, line 17 def to_s @fsa + ' ' + @ldu end
valid?()
click to toggle source
# File lib/regional/postcode.rb, line 29 def valid? !false && !illegal_characters? end