random_name_generator 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +38 -0
- data/.overcommit.yml +3 -0
- data/.rubocop.yml +26 -0
- data/.travis.yml +5 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +96 -0
- data/LICENSE +674 -0
- data/README.md +93 -0
- data/Rakefile +18 -0
- data/bin/console +17 -0
- data/bin/random_name_generator +27 -0
- data/bin/setup +8 -0
- data/config.reek +14 -0
- data/lib/random_name_generator.rb +2 -0
- data/lib/random_name_generator/languages/demonic.txt +334 -0
- data/lib/random_name_generator/languages/elven.txt +84 -0
- data/lib/random_name_generator/languages/fantasy.txt +350 -0
- data/lib/random_name_generator/languages/goblin.txt +48 -0
- data/lib/random_name_generator/languages/roman.txt +35 -0
- data/lib/random_name_generator/random_name_generator.rb +88 -0
- data/lib/random_name_generator/rng_syllable.rb +156 -0
- data/random_name_generator.gemspec +23 -0
- metadata +94 -0
@@ -0,0 +1,35 @@
|
|
1
|
+
-a
|
2
|
+
-al
|
3
|
+
-au +c
|
4
|
+
-an
|
5
|
+
-ba
|
6
|
+
-be
|
7
|
+
-bi
|
8
|
+
-br +v
|
9
|
+
-da
|
10
|
+
-di
|
11
|
+
-do
|
12
|
+
-du
|
13
|
+
-e
|
14
|
+
-eu +c
|
15
|
+
-fa
|
16
|
+
bi
|
17
|
+
be
|
18
|
+
bo
|
19
|
+
bu
|
20
|
+
nul +v
|
21
|
+
gu
|
22
|
+
da
|
23
|
+
au +c -c
|
24
|
+
fri
|
25
|
+
gus
|
26
|
+
+tus
|
27
|
+
+lus
|
28
|
+
+lius
|
29
|
+
+nus
|
30
|
+
+es
|
31
|
+
+ius -c
|
32
|
+
+cus
|
33
|
+
+tor
|
34
|
+
+cio
|
35
|
+
+tin
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require_relative 'rng_syllable'
|
2
|
+
|
3
|
+
class RandomNameGenerator
|
4
|
+
dirname = File.dirname(__FILE__)
|
5
|
+
|
6
|
+
ELVEN = File.new("#{dirname}/languages/elven.txt")
|
7
|
+
FANTASY = File.new("#{dirname}/languages/fantasy.txt")
|
8
|
+
GOBLIN = File.new("#{dirname}/languages/goblin.txt")
|
9
|
+
ROMAN = File.new("#{dirname}/languages/roman.txt")
|
10
|
+
|
11
|
+
attr_reader :pre, :pre_syllables, :sur_syllables, :mid_syllables
|
12
|
+
|
13
|
+
def initialize(filename = RandomNameGenerator::FANTASY)
|
14
|
+
@file = File.new(filename)
|
15
|
+
@pre_syllables = []
|
16
|
+
@sur_syllables = []
|
17
|
+
@mid_syllables = []
|
18
|
+
|
19
|
+
refresh
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.flip_mode
|
23
|
+
langs = [RandomNameGenerator::FANTASY,
|
24
|
+
RandomNameGenerator::ELVEN,
|
25
|
+
RandomNameGenerator::GOBLIN,
|
26
|
+
RandomNameGenerator::ROMAN]
|
27
|
+
new(langs.sample)
|
28
|
+
end
|
29
|
+
|
30
|
+
def compose(count = RandomNameGenerator.pick_number_of_syllables)
|
31
|
+
@pre = pre_syllables.sample
|
32
|
+
return @pre.to_s.capitalize if count < 2
|
33
|
+
|
34
|
+
name = determine_middle_syllables(count - 2, pre)
|
35
|
+
name << determine_last_syllable(name.last)
|
36
|
+
name.map(&:to_s).join.capitalize
|
37
|
+
end
|
38
|
+
|
39
|
+
def determine_middle_syllables(count, pre)
|
40
|
+
determine_next_syllables(count, pre, @mid_syllables)
|
41
|
+
end
|
42
|
+
|
43
|
+
def determine_last_syllable(next_to_last_syllable)
|
44
|
+
determine_next_syllable(next_to_last_syllable, @sur_syllables)
|
45
|
+
end
|
46
|
+
|
47
|
+
def determine_next_syllables(count, pre, syllables)
|
48
|
+
name = Array(pre)
|
49
|
+
return name if count < 1
|
50
|
+
next_syllable = pre
|
51
|
+
count.times do
|
52
|
+
next_syllable = determine_next_syllable(next_syllable, syllables)
|
53
|
+
name << next_syllable
|
54
|
+
end
|
55
|
+
name
|
56
|
+
end
|
57
|
+
|
58
|
+
def determine_next_syllable(this_syllable, sampler)
|
59
|
+
next_syllable = ''
|
60
|
+
loop do
|
61
|
+
next_syllable = sampler.sample
|
62
|
+
break unless this_syllable.incompatible?(next_syllable)
|
63
|
+
end
|
64
|
+
next_syllable
|
65
|
+
end
|
66
|
+
|
67
|
+
def refresh
|
68
|
+
@file.readlines.each do |line|
|
69
|
+
syllable = RNGSyllable.new(line) unless line.empty?
|
70
|
+
if syllable.prefix?
|
71
|
+
@pre_syllables.push(syllable)
|
72
|
+
elsif syllable.suffix?
|
73
|
+
@sur_syllables.push(syllable)
|
74
|
+
else
|
75
|
+
@mid_syllables.push(syllable)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.pick_number_of_syllables
|
81
|
+
distribution = [2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 5]
|
82
|
+
distribution.sample
|
83
|
+
end
|
84
|
+
|
85
|
+
def to_s
|
86
|
+
"NameGenerator (#{@file.path})"
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,156 @@
|
|
1
|
+
# SYLLABLE CLASSIFICATION:
|
2
|
+
# Name is usually composed from 3 different class of syllables, which include prefix, middle part and suffix.
|
3
|
+
# To declare syllable as a prefix in the file, insert "-" as a first character of the line.
|
4
|
+
# To declare syllable as a suffix in the file, insert "+" as a first character of the line.
|
5
|
+
# everything else is read as a middle part.
|
6
|
+
#
|
7
|
+
# NUMBER OF SYLLABLES:
|
8
|
+
# Names may have any positive number of syllables. In case of 2 syllables, name will be composed from prefix and suffix.
|
9
|
+
# In case of 1 syllable, name will be chosen from amongst the prefixes.
|
10
|
+
# In case of 3 and more syllables, name will begin with prefix, is filled with middle parts and ended with suffix.
|
11
|
+
#
|
12
|
+
# ASSIGNING RULES:
|
13
|
+
# I included a way to set 4 kind of rules for every syllable. To add rules to the syllables, write them right after the
|
14
|
+
# syllable and SEPARATE WITH WHITESPACE. (example: "aad +v -c"). The order of rules is not important.
|
15
|
+
#
|
16
|
+
# RULES:
|
17
|
+
# 1) +v means that next syllable must definitely start with a vocal.
|
18
|
+
# 2) +c means that next syllable must definitely start with a consonant.
|
19
|
+
# 3) -v means that this syllable can only be added to another syllable, that ends with a vocal.
|
20
|
+
# 4) -c means that this syllable can only be added to another syllable, that ends with a consonant.
|
21
|
+
|
22
|
+
class RNGSyllable
|
23
|
+
attr_reader :raw, :syllable, :next_syllable_requirement, :previous_syllable_requirement
|
24
|
+
|
25
|
+
VOWELS = %w(i y ɨ ʉ ɯ u ɪ ʏ ʊ ɯ ʊ e ø ɘ ɵ ɤ o ø ə ɵ ɤ o ɛ œ ɜ ɞ ʌ ɔ æ ɐ ɞ a ɶ ä ɒ ɑ).freeze
|
26
|
+
CONSONANTS = %w(b ɓ ʙ β c d ɗ ɖ ð f g h j k l ł m ɱ n ɳ p q r s t v w x y z).freeze
|
27
|
+
|
28
|
+
def initialize(args)
|
29
|
+
@raw = args
|
30
|
+
@is_prefix = false
|
31
|
+
@is_suffix = false
|
32
|
+
@next_syllable_requirement = :letter
|
33
|
+
@previous_syllable_requirement = :letter
|
34
|
+
|
35
|
+
if args.is_a?(RNGSyllable) then
|
36
|
+
parse_args(args.raw)
|
37
|
+
else
|
38
|
+
parse_args(args)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def incompatible?(next_syllable)
|
43
|
+
(next_incompatible?(next_syllable) || previous_incompatible?(next_syllable))
|
44
|
+
end
|
45
|
+
|
46
|
+
def compatible?(next_syllable)
|
47
|
+
!incompatible?(next_syllable)
|
48
|
+
end
|
49
|
+
|
50
|
+
def prefix?
|
51
|
+
@is_prefix
|
52
|
+
end
|
53
|
+
|
54
|
+
def suffix?
|
55
|
+
@is_suffix
|
56
|
+
end
|
57
|
+
|
58
|
+
def consonant_first?
|
59
|
+
CONSONANTS.include?(syllable[0])
|
60
|
+
end
|
61
|
+
|
62
|
+
def vowel_first?
|
63
|
+
VOWELS.include?(syllable[0])
|
64
|
+
end
|
65
|
+
|
66
|
+
def consonant_last?
|
67
|
+
CONSONANTS.include?(syllable[-1])
|
68
|
+
end
|
69
|
+
|
70
|
+
def vowel_last?
|
71
|
+
VOWELS.include?(syllable[-1])
|
72
|
+
end
|
73
|
+
|
74
|
+
def next_syllable_universal?
|
75
|
+
@next_syllable_requirement == :letter
|
76
|
+
end
|
77
|
+
|
78
|
+
def next_syllable_must_start_with_vowel?
|
79
|
+
@next_syllable_requirement == :vowel
|
80
|
+
end
|
81
|
+
|
82
|
+
def next_syllable_must_start_with_consonant?
|
83
|
+
@next_syllable_requirement == :consonant
|
84
|
+
end
|
85
|
+
|
86
|
+
def previous_syllable_universal?
|
87
|
+
@previous_syllable_requirement == :letter
|
88
|
+
end
|
89
|
+
|
90
|
+
def previous_syllable_must_end_with_vowel?
|
91
|
+
@previous_syllable_requirement == :vowel
|
92
|
+
end
|
93
|
+
|
94
|
+
def previous_syllable_must_end_with_consonant?
|
95
|
+
@previous_syllable_requirement == :consonant
|
96
|
+
end
|
97
|
+
|
98
|
+
def to_s
|
99
|
+
@syllable
|
100
|
+
end
|
101
|
+
|
102
|
+
def to_str
|
103
|
+
@syllable
|
104
|
+
end
|
105
|
+
|
106
|
+
private
|
107
|
+
|
108
|
+
def parse_args(args)
|
109
|
+
args = raw.to_s.strip.downcase.split(' ')
|
110
|
+
parse_syllable(args[0])
|
111
|
+
parse_flags(args[1..-1])
|
112
|
+
end
|
113
|
+
|
114
|
+
def parse_syllable(syll)
|
115
|
+
raise ArgumentError 'Empty String is not allowed.' if syll.empty?
|
116
|
+
|
117
|
+
captures = /([+-]?)(.+)/.match(syll).captures
|
118
|
+
parse_prefix(captures[0])
|
119
|
+
@syllable = captures[1]
|
120
|
+
end
|
121
|
+
|
122
|
+
def parse_prefix(prefix)
|
123
|
+
if prefix.eql?('-')
|
124
|
+
@is_prefix = true
|
125
|
+
elsif prefix.eql?('+')
|
126
|
+
@is_suffix = true
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def parse_flags(flags)
|
131
|
+
if flags.include?('+v')
|
132
|
+
@next_syllable_requirement = :vowel
|
133
|
+
elsif flags.include?('+c')
|
134
|
+
@next_syllable_requirement = :consonant
|
135
|
+
end
|
136
|
+
if flags.include?('-v')
|
137
|
+
@previous_syllable_requirement = :vowel
|
138
|
+
elsif flags.include?('-c')
|
139
|
+
@previous_syllable_requirement = :consonant
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def next_incompatible?(next_syllable)
|
144
|
+
vnc = (next_syllable_must_start_with_vowel? && next_syllable.consonant_first?)
|
145
|
+
cnv = (next_syllable_must_start_with_consonant? && next_syllable.vowel_first?)
|
146
|
+
|
147
|
+
(vnc || cnv)
|
148
|
+
end
|
149
|
+
|
150
|
+
def previous_incompatible?(next_syllable)
|
151
|
+
vlc = (vowel_last? && next_syllable.previous_syllable_must_end_with_consonant?)
|
152
|
+
clv = (consonant_last? && next_syllable.previous_syllable_must_end_with_vowel?)
|
153
|
+
|
154
|
+
(vlc || clv)
|
155
|
+
end
|
156
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'random_name_generator'
|
7
|
+
spec.version = '0.0.5'
|
8
|
+
spec.authors = ['folkengine']
|
9
|
+
spec.email = ['gaoler@electronicpanopticon.com']
|
10
|
+
spec.licenses = ['GPL-3.0']
|
11
|
+
|
12
|
+
spec.summary = 'Random Name Generator'
|
13
|
+
spec.description = 'Generates random names based upon a passed in collection of syllables.'
|
14
|
+
spec.homepage = 'https://github.com/folkengine/random_name_generator'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = 'exe'
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: random_name_generator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- folkengine
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Generates random names based upon a passed in collection of syllables.
|
42
|
+
email:
|
43
|
+
- gaoler@electronicpanopticon.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".overcommit.yml"
|
50
|
+
- ".rubocop.yml"
|
51
|
+
- ".travis.yml"
|
52
|
+
- Gemfile
|
53
|
+
- Gemfile.lock
|
54
|
+
- LICENSE
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- bin/console
|
58
|
+
- bin/random_name_generator
|
59
|
+
- bin/setup
|
60
|
+
- config.reek
|
61
|
+
- lib/random_name_generator.rb
|
62
|
+
- lib/random_name_generator/languages/demonic.txt
|
63
|
+
- lib/random_name_generator/languages/elven.txt
|
64
|
+
- lib/random_name_generator/languages/fantasy.txt
|
65
|
+
- lib/random_name_generator/languages/goblin.txt
|
66
|
+
- lib/random_name_generator/languages/roman.txt
|
67
|
+
- lib/random_name_generator/random_name_generator.rb
|
68
|
+
- lib/random_name_generator/rng_syllable.rb
|
69
|
+
- random_name_generator.gemspec
|
70
|
+
homepage: https://github.com/folkengine/random_name_generator
|
71
|
+
licenses:
|
72
|
+
- GPL-3.0
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.4.6
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Random Name Generator
|
94
|
+
test_files: []
|