Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Spanish Organization Number #897

Merged
merged 2 commits into from
Nov 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/faker/company.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ def logo
"https://pigment.github.io/fake-logos/logos/medium/color/#{rand_num}.png"
end

# Get a random Spanish organization number. See more here https://es.wikipedia.org/wiki/Número_de_identificación_fiscal
def spanish_organisation_number
# Valid leading character: A, B, C, D, E, F, G, H, J, N, P, Q, R, S, U, V, W
# 7 digit numbers
letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'N', 'P', 'Q', 'R', 'S', 'U', 'V', 'W']
base = [sample(letters), ('%07d' % rand(10 ** 7))].join
base
end

# Get a random Swedish organization number. See more here https://sv.wikipedia.org/wiki/Organisationsnummer
def swedish_organisation_number
# Valid leading digit: 1, 2, 3, 5, 6, 7, 8, 9
Expand Down
6 changes: 6 additions & 0 deletions test/test_faker_company.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ def test_buzzword
assert @tester.buzzword.match(/\w+\.?/)
end

def test_spanish_organisation_number
org_no = @tester.spanish_organisation_number
assert org_no.match(/\D\d{7}/)
assert ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'N', 'P', 'Q', 'R', 'S', 'U', 'V', 'W'].include?(org_no[0].to_s)
end

def test_swedish_organisation_number
org_no = @tester.swedish_organisation_number
assert org_no.match(/\d{10}/)
Expand Down