class Faker::Commerce
Public Class Methods
color()
click to toggle source
# File lib/faker/commerce.rb, line 5 def color fetch('color.name') end
department(max = 3, fixed_amount = false)
click to toggle source
# File lib/faker/commerce.rb, line 9 def department(max = 3, fixed_amount = false) num = max if fixed_amount num ||= 1 + rand(max) categories = categories(num) if num > 1 merge_categories(categories) else categories[0] end end
material()
click to toggle source
# File lib/faker/commerce.rb, line 26 def material fetch('commerce.product_name.material') end
price(range=0..100.0)
click to toggle source
# File lib/faker/commerce.rb, line 30 def price(range=0..100.0) random = Random::DEFAULT (random.rand(range) * 100).floor/100.0 end
product_name()
click to toggle source
# File lib/faker/commerce.rb, line 22 def product_name fetch('commerce.product_name.adjective') + ' ' + fetch('commerce.product_name.material') + ' ' + fetch('commerce.product_name.product') end
Private Class Methods
categories(num)
click to toggle source
# File lib/faker/commerce.rb, line 37 def categories(num) categories = [] while categories.length < num category = fetch('commerce.department') categories << category unless categories.include?(category) end categories end
merge_categories(categories)
click to toggle source
# File lib/faker/commerce.rb, line 47 def merge_categories(categories) separator = fetch('separator') comma_separated = categories.slice!(0...-1).join(', ') [comma_separated, categories[0]].join(separator) end