class Faker::Company

Public Class Methods

bs() click to toggle source

When a straight answer won't do, BS to the rescue!

# File lib/faker/company.rb, line 28
def bs
  translate('faker.company.bs').collect {|list| list.sample }.join(' ')
end
buzzword() click to toggle source
# File lib/faker/company.rb, line 23
def buzzword
  translate('faker.company.buzzwords').flatten.sample
end
catch_phrase() click to toggle source

Generate a buzzword-laden catch phrase.

# File lib/faker/company.rb, line 19
def catch_phrase
  translate('faker.company.buzzwords').collect {|list| list.sample }.join(' ')
end
duns_number() click to toggle source
# File lib/faker/company.rb, line 36
def duns_number
  ('%09d' % rand(10 ** 9)).gsub(/(\d\d)(\d\d\d)(\d\d\d\d)/, '\1-\2-\3')
end
ein() click to toggle source
# File lib/faker/company.rb, line 32
def ein
  ('%09d' % rand(10 ** 9)).gsub(/(\d\d)(\d\d\d\d\d\d\d)/, '\1-\2')
end
industry() click to toggle source
# File lib/faker/company.rb, line 14
def industry
  fetch('company.industry')
end
name() click to toggle source
# File lib/faker/company.rb, line 6
def name
  parse('company.name')
end
profession() click to toggle source
# File lib/faker/company.rb, line 51
def profession
  fetch('company.profession')
end
suffix() click to toggle source
# File lib/faker/company.rb, line 10
def suffix
  fetch('company.suffix')
end
swedish_organisation_number() click to toggle source
# File lib/faker/company.rb, line 46
def swedish_organisation_number
  base = ('%09d' % rand(10 ** 9))
  base + luhn_algorithm(base).to_s
end

Private Class Methods

luhn_algorithm(number) click to toggle source
# File lib/faker/company.rb, line 57
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