class Faker::Commerce

def brand

Returns:
  • (string) -
def brand
  fetch('commerce.brand')
end

def categories(num)

def categories(num)
  sample(fetch_all('commerce.department'), num)
end

def color

Returns:
  • (String) -
def color
  fetch('color.name')
end

def department(legacy_max = NOT_GIVEN, legacy_fixed_amount = NOT_GIVEN, max: 3, fixed_amount: false)

Returns:
  • (String) -

Parameters:
  • fixed_amount (Boolean) -- Fixes the amount of departments to use instead of using a range.
  • max (Integer) -- Updates the maximum number of names used to generate the department name.
def department(legacy_max = NOT_GIVEN, legacy_fixed_amount = NOT_GIVEN, max: 3, fixed_amount: false)
  warn_for_deprecated_arguments do |keywords|
    keywords << :max if legacy_max != NOT_GIVEN
    keywords << :fixed_amount if legacy_fixed_amount != NOT_GIVEN
  end
  num = max if fixed_amount
  num ||= 1 + rand(max)
  categories = categories(num)
  if categories.is_a?(Array)
    if categories.length > 1
      merge_categories(categories)
    else
      categories[0]
    end
  else
    categories
  end
end

def material

Returns:
  • (String) -
def material
  fetch('commerce.product_name.material')
end

def merge_categories(categories)

def merge_categories(categories)
  separator = fetch('separator')
  comma_separated = categories.slice!(0...-1).join(', ')
  [comma_separated, categories[0]].join(separator)
end

def price(legacy_range = NOT_GIVEN, legacy_as_string = NOT_GIVEN, range: 0..100.0, as_string: false)

Returns:
  • (Float) -

Parameters:
  • as_string (Boolean) -- Changes the return value to [String].
  • range (Range) -- A range to generate the random number within.
def price(legacy_range = NOT_GIVEN, legacy_as_string = NOT_GIVEN, range: 0..100.0, as_string: false)
  warn_for_deprecated_arguments do |keywords|
    keywords << :range if legacy_range != NOT_GIVEN
    keywords << :as_string if legacy_as_string != NOT_GIVEN
  end
  price = (rand(range) * 100).floor / 100.0
  if as_string
    price_parts = price.to_s.split('.')
    price = "#{price_parts[0]}.#{price_parts[-1].ljust(2, '0')}"
  end
  price
end

def product_name

Returns:
  • (String) -
def product_name
  "#{fetch('commerce.product_name.adjective')} #{fetch('commerce.product_name.material')} #{fetch('commerce.product_name.product')}"
end

def promotion_code(legacy_digits = NOT_GIVEN, digits: 6)

Returns:
  • (String) -

Parameters:
  • digits (Integer) -- Updates the number of numerical digits used to generate the promotion code.
def promotion_code(legacy_digits = NOT_GIVEN, digits: 6)
  warn_for_deprecated_arguments do |keywords|
    keywords << :digits if legacy_digits != NOT_GIVEN
  end
  [
    fetch('commerce.promotion_code.adjective'),
    fetch('commerce.promotion_code.noun'),
    Faker::Number.number(digits: digits)
  ].join
end

def vendor

Returns:
  • (string) -
def vendor
  fetch('commerce.vendor')
end