Class: Barometer::Query::Format::Postalcode

Inherits:
Barometer::Query::Format show all
Defined in:
lib/barometer/formats/postalcode.rb

Overview

Format: Postal Code

eg. H0H 0H0

This class is used to determine if a query is a :postalcode and what the country_code is.

Class Method Summary collapse

Methods inherited from Barometer::Query::Format

convertable_formats, converts?, is?, is_a_query?, to

Class Method Details

.country_code(query = nil) ⇒ Object



13
# File 'lib/barometer/formats/postalcode.rb', line 13

def self.country_code(query=nil); "CA"; end

.formatObject



12
# File 'lib/barometer/formats/postalcode.rb', line 12

def self.format; :postalcode; end

.regexObject



14
15
16
17
18
19
# File 'lib/barometer/formats/postalcode.rb', line 14

def self.regex
  # Rules: no D, F, I, O, Q, or U anywhere
  # Basic validation: ^[ABCEGHJ-NPRSTVXY]{1}[0-9]{1}[ABCEGHJ-NPRSTV-Z]{1}
  #   [ ]?[0-9]{1}[ABCEGHJ-NPRSTV-Z]{1}[0-9]{1}$
  /^[A-Z]{1}[\d]{1}[A-Z]{1}[ ]?[\d]{1}[A-Z]{1}[\d]{1}$/
end