Module: FFaker::Product

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

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

Methods included from ModuleUtils

const_missing, k, luhn_check, underscore, unique

Methods included from RandomUtils

#fetch_sample, #rand, #shuffle

Instance Method Details

#brandObject



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ffaker/product.rb', line 14

def brand
  case rand(0..11)
  when (0..4) then fetch_sample(B1) + fetch_sample(B2)
  when (5..10)
    [
      fetch_sample(START), fetch_sample(VOWELS), fetch_sample(SUFFIX),
      rand(0..1).zero? ? fetch_sample(ADDON) : nil
    ].join.capitalize
  when 11 then letters(2..3).to_s
  end
end

#letters(count) ⇒ Object



36
37
38
39
# File 'lib/ffaker/product.rb', line 36

def letters(count)
  max = count.is_a?(Range) ? fetch_sample(count.to_a) : count
  (0...max).map { fetch_sample(LETTERS).upcase }.join
end

#modelObject



41
42
43
44
45
# File 'lib/ffaker/product.rb', line 41

def model
  return "#{fetch_sample(LETTERS).upcase}#{rand(90)}" if rand(0..1).zero? # N90

  "#{letters(1..rand(1..2))}-#{rand(9900)}" # N-9400
end

#productObject



32
33
34
# File 'lib/ffaker/product.rb', line 32

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

#product_nameObject



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

def product_name
  return "#{fetch_sample(ADJ)} #{fetch_sample(NOUN)}" if rand(0..1).zero?

  "#{[fetch_sample(ADJ), fetch_sample(ADJ)].uniq.join(' ')} #{fetch_sample(NOUN)}"
end