Class: Faker::Commerce
- Inherits:
-
Base
- Object
- Base
- Faker::Commerce
show all
- Defined in:
- lib/faker/commerce.rb
Constant Summary
Constants inherited
from Base
Base::Letters, Base::Numbers, Base::ULetters
Class Method Summary
collapse
Methods inherited from Base
bothify, fetch, fetch_all, flexible, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, respond_to_missing?, sample, shuffle, translate, unique, with_locale
Class Method Details
.color ⇒ Object
4
5
6
|
# File 'lib/faker/commerce.rb', line 4
def color
fetch('color.name')
end
|
.department(max = 3, fixed_amount = false) ⇒ Object
16
17
18
19
20
21
22
23
24
|
# File 'lib/faker/commerce.rb', line 16
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
30
31
32
|
# File 'lib/faker/commerce.rb', line 30
def material
fetch('commerce.product_name.material')
end
|
.price(range = 0..100.0, as_string = false) ⇒ Object
34
35
36
37
38
39
40
41
|
# File 'lib/faker/commerce.rb', line 34
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
26
27
28
|
# File 'lib/faker/commerce.rb', line 26
def product_name
"#{fetch('commerce.product_name.adjective')} #{fetch('commerce.product_name.material')} #{fetch('commerce.product_name.product')}"
end
|
8
9
10
11
12
13
14
|
# File 'lib/faker/commerce.rb', line 8
def promotion_code(digits = 6)
[
fetch('commerce.promotion_code.adjective'),
fetch('commerce.promotion_code.noun'),
Faker::Number.number(digits)
].join
end
|