lib/faker/company.rb in faker-1.4.3 vs lib/faker/company.rb in faker-1.5.0

- old
+ new

@@ -14,10 +14,14 @@ # Generate a buzzword-laden catch phrase. def catch_phrase translate('faker.company.buzzwords').collect {|list| list.sample }.join(' ') end + def buzzword + translate('faker.company.buzzwords').flatten.sample + end + # When a straight answer won't do, BS to the rescue! def bs translate('faker.company.bs').collect {|list| list.sample }.join(' ') end @@ -27,14 +31,48 @@ def duns_number ('%09d' % rand(10 ** 9)).gsub(/(\d\d)(\d\d\d)(\d\d\d\d)/, '\\1-\\2-\\3') end - # Get a random company logo url in GIF format. + # Get a random company logo url in PNG format. def logo - rand_num = Random.rand(76) + 1 - "http://www.biz-logo.com/examples/#{ rand_num < 10 ? "00" : "0" }#{rand_num}.gif" + rand_num = Random.rand(13) + 1 + "http://pigment.github.io/fake-logos/logos/medium/color/#{rand_num}.png" end - end + def swedish_organisation_number + base = ('%09d' % rand(10 ** 9)) + base + luhn_algorithm(base).to_s + end + + private + + def luhn_algorithm(number) + multiplications = [] + + number.split(//).each_with_index do |digit, i| + if i % 2 == 0 + multiplications << digit.to_i * 2 + else + multiplications << digit.to_i + end + end + + sum = 0 + + multiplications.each do |num| + num.to_s.each_byte do |character| + sum += character.chr.to_i + end + end + + if sum % 10 == 0 + control_digit = 0 + else + control_digit = (sum / 10 + 1) * 10 - sum + end + + control_digit + end + end end end