From 92210df9c5db615ee2ab655c78cdb192005fac4e Mon Sep 17 00:00:00 2001 From: Tiago Farias Date: Mon, 26 Dec 2016 10:32:03 -0300 Subject: [PATCH] Refactors code in some base classes (#781) --- lib/faker/commerce.rb | 13 +++++-------- lib/faker/company.rb | 6 +++--- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/faker/commerce.rb b/lib/faker/commerce.rb index 841cfc3504..a98e1f689e 100644 --- a/lib/faker/commerce.rb +++ b/lib/faker/commerce.rb @@ -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 diff --git a/lib/faker/company.rb b/lib/faker/company.rb index c6b3c1b308..4a220a6a24 100644 --- a/lib/faker/company.rb +++ b/lib/faker/company.rb @@ -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. @@ -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