Module: FFaker::Product
Constant Summary
collapse
- B2 =
%w(nix cell sync func balt sche pod).freeze
- VOWELS =
%w(a e i o u ou ie y io).freeze
- START =
%w(tr br p ph).freeze
- SUFFIX =
%w(ck ns nce nt st ne re ffe ph).freeze
- ADDON =
%w(wood forge func).freeze
Instance Method Summary
collapse
const_missing, k, underscore
#fetch_sample, #rand, #shuffle
Instance Method Details
#brand ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/ffaker/product.rb', line 14
def brand
case rand(12)
when (0..4) then fetch_sample(B1) + fetch_sample(B2)
when (5..10) then
[
fetch_sample(START), fetch_sample(VOWELS), fetch_sample(SUFFIX),
rand(2).zero? ? fetch_sample(ADDON) : nil
].join.capitalize
when 11 then letters(2..3).to_s
end
end
|
#letters(n) ⇒ Object
37
38
39
40
|
# File 'lib/ffaker/product.rb', line 37
def letters(n)
max = n.is_a?(Range) ? fetch_sample(n.to_a) : n
(0...max).map { fetch_sample(LETTERS).upcase }.join
end
|
#model ⇒ Object
42
43
44
45
46
47
|
# File 'lib/ffaker/product.rb', line 42
def model
case rand(2)
when 0 then "#{fetch_sample(LETTERS).upcase}#{rand(90)}" when 1 then "#{letters(1..rand(1..2))}-#{rand(9900)}" end
end
|
#product ⇒ Object
33
34
35
|
# File 'lib/ffaker/product.rb', line 33
def product
"#{brand} #{product_name}"
end
|
#product_name ⇒ Object
26
27
28
29
30
31
|
# File 'lib/ffaker/product.rb', line 26
def product_name
case rand(2)
when 0 then "#{fetch_sample(ADJ)} #{fetch_sample(NOUN)}"
when 1 then "#{[fetch_sample(ADJ), fetch_sample(ADJ)].uniq.join(' ')} #{fetch_sample(NOUN)}"
end
end
|