Module: Faker::Product

Extended by:
ModuleUtils, Product
Included in:
Product
Defined in:
lib/ffakerer/product.rb

Constant Summary collapse

B2 =
k %w(nix cell sync func balt sche pod)
VOWELS =
k %w(a e i o u ou ie y io)
START =
k %w(tr br p ph)
SUFFIX =
k %w(ck ns nce nt st ne re ffe ph)
ADDON =
k %w(wood forge func)

Instance Method Summary collapse

Methods included from ModuleUtils

const_missing, k, underscore

Instance Method Details

#brandObject



8
9
10
11
12
13
14
# File 'lib/ffakerer/product.rb', line 8

def brand
  case rand(12)
  when (0..4) then B1.rand + B2.rand
  when (5..10) then "#{START.rand}#{VOWELS.rand}#{SUFFIX.rand}#{ADDON.rand if rand(2)==0}".capitalize
  when 11 then "#{letters(2..3)}"
  end
end

#letters(n) ⇒ Object



27
28
29
30
# File 'lib/ffakerer/product.rb', line 27

def letters(n)
  max = n.is_a?(Range) ? n.to_a.shuffle.first : n
  (0...max).map { LETTERS.rand.upcase }.join
end

#modelObject



32
33
34
35
36
37
# File 'lib/ffakerer/product.rb', line 32

def model
  case rand(2)
  when 0 then "#{LETTERS.rand.upcase}#{rand(90)}"   # N90
  when 1 then "#{letters(1..rand(1..2))}-#{rand(9900)}"         # N-9400
  end
end

#productObject



23
24
25
# File 'lib/ffakerer/product.rb', line 23

def product
  "#{brand} #{product_name}"
end

#product_nameObject



16
17
18
19
20
21
# File 'lib/ffakerer/product.rb', line 16

def product_name
  case rand(2)
  when 0 then "#{ADJ.rand} #{NOUN.rand}"
  when 1 then "#{[ADJ.rand, ADJ.rand].uniq.join(" ")} #{NOUN.rand}"
  end
end