class FactoryHelper::Commerce

Public Class Methods

color() click to toggle source
# File lib/factory-helper/commerce.rb, line 6
def color
  fetch('commerce.color')
end
department(max = 3, fixed_amount = false) click to toggle source
# File lib/factory-helper/commerce.rb, line 10
def department(max = 3, fixed_amount = false)
  num = max if fixed_amount
  num ||= 1 + FactoryHelper::Config.random.rand(max)

  categories = categories(num)

  if num > 1
    merge_categories(categories)
  else
    categories[0]
  end
end
material() click to toggle source
# File lib/factory-helper/commerce.rb, line 27
def material
  fetch('commerce.product_name.material')
end
price() click to toggle source
# File lib/factory-helper/commerce.rb, line 31
def price
  random = FactoryHelper::Config.random
  (random.rand(0..100.0) * 100).floor/100.0
end
product_name() click to toggle source
# File lib/factory-helper/commerce.rb, line 23
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/factory-helper/commerce.rb, line 38
def categories(num)
  categories = []
  while categories.length < num do
    category = fetch('commerce.department')
    categories << category unless categories.include?(category)
  end

  categories
end
merge_categories(categories) click to toggle source
# File lib/factory-helper/commerce.rb, line 48
def merge_categories(categories)
  separator = fetch('separator')
  comma_separated = categories.slice!(0...-1).join(', ')

  [comma_separated, categories[0]].join(separator)
end