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(max: 3, fixed_amount: false) ⇒ String
Produces a random department.
-
.material ⇒ String
Produces a random material.
-
.price(range: 0..100.0, as_string: false) ⇒ Float
Produces a random product price.
-
.product_name ⇒ String
Produces a random product name.
-
.promotion_code(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, generate, 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
125 126 127 |
# File 'lib/faker/default/commerce.rb', line 125 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(max: 3, fixed_amount: false) ⇒ String
Produces a random department.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/faker/default/commerce.rb', line 51 def department(max: 3, fixed_amount: false) 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.
90 91 92 |
# File 'lib/faker/default/commerce.rb', line 90 def material fetch('commerce.product_name.material') end |
.price(range: 0..100.0, as_string: false) ⇒ Float
Produces a random product price.
106 107 108 109 110 111 112 113 |
# File 'lib/faker/default/commerce.rb', line 106 def price(range: 0..100.0, as_string: false) 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.
77 78 79 |
# File 'lib/faker/default/commerce.rb', line 77 def product_name "#{fetch('commerce.product_name.adjective')} #{fetch('commerce.product_name.material')} #{fetch('commerce.product_name.product')}" end |
.promotion_code(digits: 6) ⇒ String
Produces a random promotion code.
30 31 32 33 34 35 36 |
# File 'lib/faker/default/commerce.rb', line 30 def promotion_code(digits: 6) [ 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
139 140 141 |
# File 'lib/faker/default/commerce.rb', line 139 def vendor fetch('commerce.vendor') end |