-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnamesGenerator.rb
42 lines (37 loc) · 1.5 KB
/
namesGenerator.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
#
# This Generator creates names similar to those generated by the algorithm
# used on Anarres, the desert planet of the exile anarchists, in the
# 'ambiguous utopia' 'The Dispossessed' by Ursula K. Le Guin
#
class NamesGenerator
VOWELS = ['a', 'e', 'i', 'o', 'u']
CONSONANTS = ('a'..'z').to_a - VOWELS
CONSONANTS_TO_AVOID = ['c','h','j','q','w','x','y']
COMBINED_CONSONANTS = ['ch','gv','kv','sh']
COMBINED_CONSONANTS_FOR_PART = { :begin => ['sk','tr'],
:middle => ['rd', 'rr', 'rz','ss'],
:end => ['ks']}
NON_VOWEL_SOUNDS = CONSONANTS - CONSONANTS_TO_AVOID + COMBINED_CONSONANTS
NON_VOWEL_SOUNDS_FOR_PART = {:begin => NON_VOWEL_SOUNDS + COMBINED_CONSONANTS_FOR_PART[:begin],
:middle => NON_VOWEL_SOUNDS + COMBINED_CONSONANTS_FOR_PART[:middle],
:end => NON_VOWEL_SOUNDS + COMBINED_CONSONANTS_FOR_PART[:end]}
def self.generate_name
(NON_VOWEL_SOUNDS_FOR_PART[:begin].sample +
VOWELS.sample +
NON_VOWEL_SOUNDS_FOR_PART[:middle].sample +
VOWELS.sample +
NON_VOWEL_SOUNDS_FOR_PART[:end].sample).capitalize
end
def self.name
#names should be 5 or 6 letters long
begin
proposal = self.generate_name
end until proposal.length == 5 || proposal.length == 6
#todo: check of name already given to living person
#todo: check if non-dictionary-word
proposal
end
end
10.times do
puts NamesGenerator.name
end