diff --git a/CHANGELOG.md b/CHANGELOG.md index a8d6f9f770..5f00e9e2d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,10 @@ # Change Log ## HEAD Unreleased -### Latest update: 2018-06-01 +### Latest update: 2018-06-02 ### Feature Request +- [PR #1101](https://github.com/stympy/faker/pull/1101) Add Faker::Company.czech_organisation_number [@jindrichskupa](https://github.com/jindrichskupa) - [PR #1265](https://github.com/stympy/faker/pull/1265) Add Faker::WorldCup [@snayrouz](https://github.com/snayrouz) - [PR #1141](https://github.com/stympy/faker/pull/1141) Add Faker::Coffee.intensifier [@oyeanuj](https://github.com/oyeanuj) - [PR #1260](https://github.com/stympy/faker/pull/1260) Add Faker::Auto features to Faker::Vehicle [@mrstebo](https://github.com/mrstebo) diff --git a/doc/company.md b/doc/company.md index 236bbbcf3b..c64f0bd0e4 100644 --- a/doc/company.md +++ b/doc/company.md @@ -33,6 +33,8 @@ Faker::Company.profession #=> "firefighter" Faker::Company.swedish_organisation_number #=> "7962578022" +Faker::Company.czech_organisation_number #=> "77778171" + Faker::Company.french_siren_number #=> "819489626" Faker::Company.french_siret_number #=> "81948962600013" diff --git a/lib/faker/company.rb b/lib/faker/company.rb index 8daaec5841..916f38b598 100644 --- a/lib/faker/company.rb +++ b/lib/faker/company.rb @@ -71,6 +71,17 @@ def swedish_organisation_number base + luhn_algorithm(base).to_s end + def czech_organisation_number + sum = 0 + base = [] + [8, 7, 6, 5, 4, 3, 2].each do |weight| + base << sample((0..9).to_a) + sum += (weight * base.last) + end + base << (11 - (sum % 11)) % 10 + base.join + end + # Get a random French SIREN number. See more here https://fr.wikipedia.org/wiki/Syst%C3%A8me_d%27identification_du_r%C3%A9pertoire_des_entreprises def french_siren_number base = (1..8).map { rand(10) }.join diff --git a/test/test_faker_company.rb b/test/test_faker_company.rb index 5ced3b3ee6..805147e592 100644 --- a/test/test_faker_company.rb +++ b/test/test_faker_company.rb @@ -39,6 +39,13 @@ def test_swedish_organisation_number assert org_no[9] == @tester.send(:luhn_algorithm, org_no[0..8]).to_s end + def test_czech_organisation_number + org_no = @tester.czech_organisation_number + assert org_no.match(/\d{8}/) + assert [0, 1, 2, 3, 5, 6, 7, 8, 9].include?(org_no[0].to_i) + assert czech_o_n_checksum(org_no) == org_no[-1].to_i + end + def test_french_siren_number siren = @tester.french_siren_number assert siren.match(/\A\d{9}\z/) @@ -109,6 +116,16 @@ def test_mod11 private + def czech_o_n_checksum(org_no) + weights = [8, 7, 6, 5, 4, 3, 2] + sum = 0 + digits = org_no.split('').map(&:to_i) + weights.each_with_index.map do |w, i| + sum += (w * digits[i]) + end + (11 - (sum % 11)) % 10 + end + def abn_checksum(abn) abn_weights = [10, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19]