Module: CAPostalCode

Defined in:
lib/ca_postal_code.rb,
lib/ca_postal_code/version.rb

Constant Summary collapse

REGIONS =
{
  NL: ?A,
  NS: ?B,
  PE: ?C,
  NB: ?E,
  QC: [?G, ?H, ?J],
  ON: [?K, ?L, ?M, ?N, ?P],
  MB: ?R,
  SK: ?S,
  AB: ?T,
  BC: ?V,
  NU: /^X0[A-C]/,
  NT: [/^X0[EG]/, /^X1A/],
  YT: ?Y,
}
VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.guess_region(string) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/ca_postal_code.rb', line 20

def self.guess_region(string)
  entry = patterns.detect do |pattern, region|
    pattern.match?(string)
  end

  entry[1] if entry
end

.patternsObject

Lists the patterns the library will use. It is made public only to make the implementation visible.



30
31
32
# File 'lib/ca_postal_code.rb', line 30

def self.patterns
  @@patterns
end