Sha256: c4ec4304f9edde5f40d900d14ae5ee862188afd23197afeb15a1d932125328c5

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

# encoding: utf-8

module FFaker
  module Product
    extend ModuleUtils
    extend self

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

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

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

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

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

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ffaker-2.2.0 lib/ffaker/product.rb
ffaker-2.1.0 lib/ffaker/product.rb