Skip to content

Commit

Permalink
Refactors code in some base classes (#781)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagofsilva authored and stympy committed Dec 26, 2016
1 parent 998b6d1 commit 92210df
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
13 changes: 5 additions & 8 deletions lib/faker/commerce.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,22 @@ def department(max = 3, fixed_amount = false)

categories = categories(num)

if num > 1
merge_categories(categories)
else
categories[0]
end
return merge_categories(categories) if num > 1
categories[0]
end

def product_name
fetch('commerce.product_name.adjective') + ' ' + fetch('commerce.product_name.material') + ' ' + fetch('commerce.product_name.product')
"#{fetch('commerce.product_name.adjective')} #{fetch('commerce.product_name.material')} #{fetch('commerce.product_name.product')}"
end

def material
fetch('commerce.product_name.material')
end

def price(range=0..100.0, string=false)
def price(range=0..100.0, as_string=false)
random = Random::DEFAULT
price = (random.rand(range) * 100).floor/100.0
if string
if as_string
price_parts = price.to_s.split('.')
price = price_parts[0] + price_parts[-1].ljust(2, "0")
end
Expand Down
6 changes: 3 additions & 3 deletions lib/faker/company.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ def bs
end

def ein
('%09d' % rand(10 ** 9)).gsub(/(\d\d)(\d\d\d\d\d\d\d)/, '\\1-\\2')
('%09d' % rand(10 ** 9)).gsub(/(\d{2})(\d{7})/, '\\1-\\2')
end

def duns_number
('%09d' % rand(10 ** 9)).gsub(/(\d\d)(\d\d\d)(\d\d\d\d)/, '\\1-\\2-\\3')
('%09d' % rand(10 ** 9)).gsub(/(\d{2})(\d{3})(\d{4})/, '\\1-\\2-\\3')
end

# Get a random company logo url in PNG format.
Expand All @@ -54,7 +54,7 @@ def swedish_organisation_number

def australian_business_number
base = ('%09d' % rand(10 ** 9))
abn = '00' + base
abn = "00#{base}"

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

0 comments on commit 92210df

Please sign in to comment.