Class: Faker::Commerce
Constant Summary
Constants inherited from Base
Base::LLetters, Base::Letters, Base::NOT_GIVEN, Base::Numbers, Base::ULetters
Class Method Summary collapse
-
.brand ⇒ string
Produces a randomized string of a brand name.
-
.color ⇒ String
Produces a random color.
-
.department(legacy_max = NOT_GIVEN, legacy_fixed_amount = NOT_GIVEN, max: 3, fixed_amount: false) ⇒ String
Produces a random department.
-
.material ⇒ String
Produces a random material.
-
.price(legacy_range = NOT_GIVEN, legacy_as_string = NOT_GIVEN, range: 0..100.0, as_string: false) ⇒ Float
Produces a random product price.
-
.product_name ⇒ String
Produces a random product name.
-
.promotion_code(legacy_digits = NOT_GIVEN, digits: 6) ⇒ String
Produces a random promotion code.
-
.vendor ⇒ string
Produces a randomized string of a vendor name.
Methods inherited from Base
bothify, disable_enforce_available_locales, fetch, fetch_all, flexible, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, resolve, respond_to_missing?, sample, shuffle, translate, unique, with_locale
Class Method Details
.brand ⇒ string
Produces a randomized string of a brand name
139 140 141 |
# File 'lib/faker/default/commerce.rb', line 139 def brand fetch('commerce.brand') end |
.color ⇒ String
Produces a random color.
15 16 17 |
# File 'lib/faker/default/commerce.rb', line 15 def color fetch('color.name') end |
.department(legacy_max = NOT_GIVEN, legacy_fixed_amount = NOT_GIVEN, max: 3, fixed_amount: false) ⇒ String
Produces a random department.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/faker/default/commerce.rb', line 55 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 |
.material ⇒ String
Produces a random material.
99 100 101 |
# File 'lib/faker/default/commerce.rb', line 99 def material fetch('commerce.product_name.material') end |
.price(legacy_range = NOT_GIVEN, legacy_as_string = NOT_GIVEN, range: 0..100.0, as_string: false) ⇒ Float
Produces a random product price.
115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/faker/default/commerce.rb', line 115 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 |
.product_name ⇒ String
Produces a random product name.
86 87 88 |
# File 'lib/faker/default/commerce.rb', line 86 def product_name "#{fetch('commerce.product_name.adjective')} #{fetch('commerce.product_name.material')} #{fetch('commerce.product_name.product')}" end |
.promotion_code(legacy_digits = NOT_GIVEN, digits: 6) ⇒ String
Produces a random promotion code.
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/faker/default/commerce.rb', line 30 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 |
.vendor ⇒ string
Produces a randomized string of a vendor name
153 154 155 |
# File 'lib/faker/default/commerce.rb', line 153 def vendor fetch('commerce.vendor') end |