Sha256: a10ba6918a68bb8da9742464a8b121122deccbf53d83b0b84cdc6338912d71e4
Contents?: true
Size: 970 Bytes
Versions: 1
Compression:
Stored size: 970 Bytes
Contents
require "ca_postal_code/version" module CAPostalCode 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, } def self.guess_region(string) entry = patterns.detect do |pattern, region| pattern.match?(string) end entry[1] if entry end # Lists the patterns the library will use. It is made public only to # make the implementation visible. def self.patterns @@patterns end private def self.add_pattern(pattern, region) unless pattern.is_a?(Regexp) pattern = Regexp.new("^" + pattern) end @@patterns[pattern] = region.to_s end @@patterns = {} REGIONS.each do |region, patterns| unless patterns.is_a?(Array) patterns = [patterns] end patterns.each do |pattern| add_pattern(pattern, region) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ca_postal_code-0.1.0 | lib/ca_postal_code.rb |