Class: Faker::Commerce
- Inherits:
-
Base
- Object
- Base
- Faker::Commerce
show all
- Defined in:
- lib/faker/default/commerce.rb
Constant Summary
Constants inherited
from Base
Base::Letters, Base::Numbers, Base::ULetters
Class Method Summary
collapse
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
.color ⇒ Object
6
7
8
|
# File 'lib/faker/default/commerce.rb', line 6
def color
fetch('color.name')
end
|
.department(max = 3, fixed_amount = false) ⇒ Object
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/faker/default/commerce.rb', line 18
def department(max = 3, fixed_amount = false)
num = max if fixed_amount
num ||= 1 + rand(max)
categories = categories(num)
return merge_categories(categories) if num > 1
categories[0]
end
|
.material ⇒ Object
33
34
35
|
# File 'lib/faker/default/commerce.rb', line 33
def material
fetch('commerce.product_name.material')
end
|
.price(range = 0..100.0, as_string = false) ⇒ Object
37
38
39
40
41
42
43
44
|
# File 'lib/faker/default/commerce.rb', line 37
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 ⇒ Object
29
30
31
|
# File 'lib/faker/default/commerce.rb', line 29
def product_name
"#{fetch('commerce.product_name.adjective')} #{fetch('commerce.product_name.material')} #{fetch('commerce.product_name.product')}"
end
|
10
11
12
13
14
15
16
|
# File 'lib/faker/default/commerce.rb', line 10
def promotion_code(digits = 6)
[
fetch('commerce.promotion_code.adjective'),
fetch('commerce.promotion_code.noun'),
Faker::Number.number(digits)
].join
end
|