Skip to content

Commit

Permalink
Added AddressCA for Canada-specific info
Browse files Browse the repository at this point in the history
info includes Canadian provinces, province abbreviations and postal codes
  • Loading branch information
steveclarke committed Nov 10, 2011
1 parent 325d188 commit 4ac5bbe
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/ffaker.rb
Expand Up @@ -23,6 +23,7 @@ def self.bothify(string)

autoload :Address, 'ffaker/address'
autoload :AddressDE, 'ffaker/address_de'
autoload :AddressCA, 'ffaker/address_ca'
autoload :Company, 'ffaker/company'
autoload :Education, 'ffaker/education'
autoload :Geolocation, 'ffaker/geolocation'
Expand Down
30 changes: 30 additions & 0 deletions lib/ffaker/address_ca.rb
@@ -0,0 +1,30 @@
module Faker
module AddressCA
include Faker::Address
extend ModuleUtils
extend self

def postal_code
Faker.bothify(POSTAL_CODE_FORMATS.rand).upcase
end

def province
PROVINCE.rand
end

def province_abbr
PROVINCE_ABBRS.rand
end

POSTAL_CODE_FORMATS = k ['?#? #?#']

PROVINCE = k [
'Newfoundland and Labrador', 'Nova Scotia', 'Prince Edward Island',
'New Brunswick', 'Quebec', 'Ontario', 'Manitoba', 'Saskatchewan',
'Alberta', 'British Columbia', 'Yukon', 'Northwest Territories',
'Nunavut'
]

PROVINCE_ABBRS = k %w(NL NS PE NB QC ON MB SK AB BC YT NT NU)
end
end
15 changes: 15 additions & 0 deletions test/test_address_ca.rb
@@ -0,0 +1,15 @@
require 'helper'

class TestAddressCA < Test::Unit::TestCase
def test_province
assert_match /[ a-z]/, Faker::AddressCA.province
end

def test_province_abbr
assert_match /[A-Z][A-Z]/, Faker::AddressCA.province_abbr
end

def test_postal_code
assert_match /[A-Z]\d[A-Z]\W\d[A-Z]\d/, Faker::AddressCA.postal_code
end
end

0 comments on commit 4ac5bbe

Please sign in to comment.