-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnamer.rb
67 lines (55 loc) · 1.28 KB
/
namer.rb
1
2
3
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
require 'yaml'
class RoadWarriorNamer
def name_me
name = ''
base = get_word
if rand > 1.0 / 3
word = get_word
base += word unless base =~ Regexp.new(word)
end
base.capitalize!
name = base
if rand > 2.0 / 3
prefix = get_prefix.capitalize
name = prefix + ' ' + name
end
if rand > 3.0 / 4
second = ''
word = get_word
second += word unless name =~ Regexp.new(word)
if rand > 2.0 / 3
word = get_word
second += word unless name =~ Regexp.new(word)
end
name += (" " + second.capitalize) unless second.empty?
end
if rand > 3.0 / 4
suffix = get_suffix
if suffix [0] == ','
name = name + suffix
else
name = name + ' ' + suffix
end
end
name
end
def get_word
names.sample.strip.downcase
end
def get_prefix
prefixes.sample.strip
end
def get_suffix
suffixes.sample.strip
end
def names
@names ||= YAML.load_file File.expand_path('config/names.yml')
end
def prefixes
@prefixes ||= YAML.load_file File.expand_path('config/prefixes.yml')
end
def suffixes
@suffixes ||= YAML.load_file File.expand_path('config/suffixes.yml')
end
end
puts RoadWarriorNamer.new.name_me