Class: Ryba::Company

Inherits:
Object
  • Object
show all
Defined in:
lib/ryba/company.rb

Class Method Summary collapse

Class Method Details

.name(opts = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ryba/company.rb', line 4

def name(opts = {})
  ind = opts[:industries] || opts[:industry] || 3
  industries = case ind
               when Numeric
                 Ryba.pick_multi(Data::Industries, ind)
               when Array
                 ind
               when Symbol
                 [ ind ]
               else
                 raise ArgumentError
               end

  words = (industries << :common).map { |i| Data::CompanyNameParts[i] }.flatten

  last_word_variants = words.select { |w| !w.start_with?('-') }
  inner_word_variants = words.select { |w| !w.start_with?('$') }

  word_count = (opts[:solidity] || 1) + 1

  last_word = Ryba.pick(last_word_variants)

  parts = Ryba.pick_multi(inner_word_variants - [last_word], word_count - 1)
  name = (parts << last_word).map { |w| w.sub(/^[-$]/, '') } * ''

  if rand(5) > 2
    suffix = Ryba.pick(Data::CompanyNameSuffixes)

    if suffix.start_with?('-')
      name << suffix
    else
      name = "#{name} #{suffix}"
    end
  end

  name
end