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

Add yard docs for Faker::Company #1915

Merged
merged 11 commits into from Feb 14, 2020
240 changes: 236 additions & 4 deletions lib/faker/default/company.rb
Expand Up @@ -5,57 +5,163 @@ class Company < Base
flexible :company

class << self
##
# Produces a company name.
#
# @return [String]
#
# @example
# Faker::Company.name #=> "Roberts Inc"
#
# @faker.version 1.6.0
def name
parse('company.name')
end

##
# Produces a company suffix.
#
# @return [String]
#
# @example
# Faker::Company.suffix #=> "LLC"
#
# @faker.version 1.6.0
def suffix
fetch('company.suffix')
end

##
# Produces a company industry.
#
# @return [String]
#
# @example
# Faker::Company.industry #=> "Food & Beverages"
#
# @faker.version 1.6.0
def industry
fetch('company.industry')
end

# Generate a buzzword-laden catch phrase.
##
# Produces a company catch phrase.
#
# @return [String]
#
# @example
# Faker::Company.catch_phrase #=> "Grass-roots grid-enabled portal"
#
# @faker.version 1.6.0
def catch_phrase
translate('faker.company.buzzwords').collect { |list| sample(list) }.join(' ')
end

##
# Produces a company buzzword.
#
# @return [String]
#
# @example
# Faker::Company.buzzword #=> "flexibility"
#
# @faker.version 1.8.7
def buzzword
sample(translate('faker.company.buzzwords').flatten)
end

##
# Produces some company BS.
#
# @return [String]
#
# @example
# Faker::Company.bs #=> "empower customized functionalities"
#
# @faker.version 1.6.0
# When a straight answer won't do, BS to the rescue!
def bs
translate('faker.company.bs').collect { |list| sample(list) }.join(' ')
end

##
# Produces a company EIN (Employer Identification Number).
#
# @return [String]
#
# @example
# Faker::Company.ein #=> "07-4009024"
#
# @faker.version 1.6.0
def ein
format('%09d', rand(10**9)).gsub(/(\d{2})(\d{7})/, '\\1-\\2')
end

##
# Produces a company duns number.
#
# @return [String]
#
# @example
# Faker::Company.duns_number #=> "70-655-5105"
#
# @faker.version 1.6.0
def duns_number
format('%09d', rand(10**9)).gsub(/(\d{2})(\d{3})(\d{4})/, '\\1-\\2-\\3')
end

##
# Produces a company logo.
#
# @return [String]
#
# @example
# Faker::Company.logo #=> "https://pigment.github.io/fake-logos/logos/medium/color/12.png"
#
# @faker.version 1.8.7
# Get a random company logo url in PNG format.
def logo
rand_num = rand(1..13)
"https://pigment.github.io/fake-logos/logos/medium/color/#{rand_num}.png"
end

##
# Produces a company type.
#
# @return [String]
#
# @example
# Faker::Company.type #=> "Partnership"
#
# @faker.version 1.8.7
def type
fetch('company.type')
end

##
# Produces a company profession.
#
# @return [String]
#
# @example
# Faker::Company.profession #=> "factory worker"
#
# @faker.version 1.6.0
def profession
fetch('company.profession')
end

# rubocop:disable Style/AsciiComments
# Get a random Spanish organization number. See more here https://es.wikipedia.org/wiki/Número_de_identificación_fiscal
# rubocop:enable Style/AsciiComments
##
# Produces a company spanish organisation number.
#
# @return [String]
#
# @example
# Faker::Company.spanish_organisation_number #=> "D6819358"
#
# @faker.version 1.8.5
#
# Get a random Spanish organization number. See more here https://es.wikipedia.org/wiki/N%C3%BAmero_de_identificaci%C3%B3n_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
Expand All @@ -64,6 +170,15 @@ def spanish_organisation_number
base
end

##
# Produces a company swedish organisation number.
#
# @return [String]
#
# @example
# Faker::Company.swedish_organisation_number #=> "3866029808"
#
# @faker.version 1.7.0
# 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 All @@ -73,6 +188,15 @@ def swedish_organisation_number
base + luhn_algorithm(base).to_s
end

##
# Produces a company czech organisation number.
#
# @return [String]
#
# @example
# Faker::Company.czech_organisation_number #=> "90642741"
#
# @faker.version 1.9.1
def czech_organisation_number
sum = 0
base = []
Expand All @@ -84,18 +208,45 @@ def czech_organisation_number
base.join
end

##
# Produces a company french siren number.
#
# @return [String]
#
# @example
# Faker::Company.french_siren_number #=> "163417827"
#
# @faker.version 1.8.5
# 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
base + luhn_algorithm(base).to_s
end

##
# Produces a company french siret number.
#
# @return [String]
#
# @example
# Faker::Company.french_siret_number #=> "76430067900496"
#
# @faker.version 1.8.5
def french_siret_number
location = rand(100).to_s.rjust(4, '0')
org_no = french_siren_number + location
org_no + luhn_algorithm(org_no).to_s
end

##
# Produces a company norwegian organisation number.
#
# @return [String]
#
# @example
# Faker::Company.norwegian_organisation_number #=> "842457173"
#
# @faker.version 1.8.0
# Get a random Norwegian organization number. Info: https://www.brreg.no/om-oss/samfunnsoppdraget-vart/registera-vare/einingsregisteret/organisasjonsnummeret/
def norwegian_organisation_number
# Valid leading digit: 8, 9
Expand All @@ -107,13 +258,31 @@ def norwegian_organisation_number
base + mod11_check.to_s
end

##
# Produces a company australian business number.
#
# @return [String]
#
# @example
# Faker::Company.australian_business_number #=> "93579396170"
#
# @faker.version 1.6.4
def australian_business_number
base = format('%09d', rand(10**9))
abn = "00#{base}"

(99 - (abn_checksum(abn) % 89)).to_s + base
end

##
# Produces a company polish taxpayer identification_number.
#
# @return [String]
#
# @example
# Faker::Company.polish_taxpayer_identification_number #=> "2767549463"
#
# @faker.version 1.9.1
# Get a random Polish taxpayer identification number More info https://pl.wikipedia.org/wiki/NIP
def polish_taxpayer_identification_number
result = []
Expand All @@ -125,6 +294,15 @@ def polish_taxpayer_identification_number
result.join('')
end

##
# Produces a company polish register of national economy.
#
# @return [String]
#
# @example
# Faker::Company.polish_register_of_national_economy #=> "788435970"
#
# @faker.version 1.9.1
# Get a random Polish register of national economy number. More info https://pl.wikipedia.org/wiki/REGON
def polish_register_of_national_economy(legacy_length = NOT_GIVEN, length: 9)
warn_for_deprecated_arguments do |keywords|
Expand All @@ -141,22 +319,67 @@ def polish_register_of_national_economy(legacy_length = NOT_GIVEN, length: 9)
random_digits.join('')
end

##
# Produces a company south african pty ltd registration number.
#
# @return [String]
#
# @example
# Faker::Company.south_african_pty_ltd_registration_number #=> "7043/2400717902/07"
#
# @faker.version 1.9.2
def south_african_pty_ltd_registration_number
regexify(/\d{4}\/\d{4,10}\/07/)
end

##
# Produces a company south african close corporation registration number.
#
# @return [String]
#
# @example
# Faker::Company.south_african_close_corporation_registration_number #=> "CK38/5739937418/23"
#
# @faker.version 1.9.2
def south_african_close_corporation_registration_number
regexify(/(CK\d{2}|\d{4})\/\d{4,10}\/23/)
end

##
# Produces a company south african listed company registration number.
#
# @return [String]
#
# @example
# Faker::Company.south_african_listed_company_registration_number #=> "2512/87676/06"
#
# @faker.version 1.9.2
def south_african_listed_company_registration_number
regexify(/\d{4}\/\d{4,10}\/06/)
end

##
# Produces a company south african trust registration number.
#
# @return [String]
#
# @example
# Faker::Company.south_african_trust_registration_number #=> "IT5673/937519896"
#
# @faker.version 1.9.2
def south_african_trust_registration_number
regexify(/IT\d{2,4}\/\d{2,10}/)
end

##
# Produces a company brazilian company number.
#
# @return [String]
#
# @example
# Faker::Company.brazilian_company_number #=> "37205322000500"
#
# @faker.version 1.9.2
def brazilian_company_number(legacy_formatted = NOT_GIVEN, formatted: false)
warn_for_deprecated_arguments do |keywords|
keywords << :formatted if legacy_formatted != NOT_GIVEN
Expand All @@ -176,6 +399,15 @@ def brazilian_company_number(legacy_formatted = NOT_GIVEN, formatted: false)
formatted ? format('%s.%s.%s/%s-%s', *number.scan(/(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})/).flatten) : number
end

##
# Produces a company sic code.
#
# @return [String]
#
# @example
# Faker::Company.sic_code #=> "7383"
#
# @faker.version 1.9.4
def sic_code
fetch('company.sic_code')
end
Expand Down