lib/ffaker/product.rb in ffaker-2.2.0 vs lib/ffaker/product.rb in ffaker-2.3.0

- old
+ new

@@ -3,43 +3,47 @@ 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) + 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 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)}" + 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 def product_name case rand(2) - when 0 then "#{ADJ.sample} #{NOUN.sample}" - when 1 then "#{[ADJ.sample, ADJ.sample].uniq.join(" ")} #{NOUN.sample}" + 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 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 + max = n.is_a?(Range) ? fetch_sample(n.to_a) : n + (0...max).map { fetch_sample(LETTERS).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 + when 0 then "#{fetch_sample(LETTERS).upcase}#{rand(90)}" # N90 + when 1 then "#{letters(1..rand(1..2))}-#{rand(9900)}" # N-9400 end end end end