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, sample, shuffle, translate, unique, with_locale
Class Method Details
.color ⇒ Object
5
6
7
|
# File 'lib/faker/commerce.rb', line 5
def color
fetch('color.name')
end
|
.department(max = 3, fixed_amount = false) ⇒ Object
17
18
19
20
21
22
23
24
25
|
# File 'lib/faker/commerce.rb', line 17
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
31
32
33
|
# File 'lib/faker/commerce.rb', line 31
def material
fetch('commerce.product_name.material')
end
|
.price(range = 0..100.0, as_string = false) ⇒ Object
35
36
37
38
39
40
41
42
|
# File 'lib/faker/commerce.rb', line 35
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
27
28
29
|
# File 'lib/faker/commerce.rb', line 27
def product_name
"#{fetch('commerce.product_name.adjective')} #{fetch('commerce.product_name.material')} #{fetch('commerce.product_name.product')}"
end
|
9
10
11
12
13
14
15
|
# File 'lib/faker/commerce.rb', line 9
def promotion_code(digits = 6)
[
fetch('commerce.promotion_code.adjective'),
fetch('commerce.promotion_code.noun'),
Faker::Number.number(digits)
].join
end
|