random_name_generator 1.0.3 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
metadata CHANGED
@@ -1,80 +1,65 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: random_name_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - folkengine
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-20 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'
11
+ date: 2021-08-08 00:00:00.000000000 Z
12
+ dependencies: []
41
13
  description: Generates random names based upon custom collections of syllables. Styles
42
- include Elvish, Fantasy, Goblin, and Roman
14
+ include Elvish, Fantasy, Goblin, and Roman.
43
15
  email:
44
16
  - gaoler@electronicpanopticon.com
45
- executables: []
17
+ executables:
18
+ - random_name_generator
46
19
  extensions: []
47
20
  extra_rdoc_files: []
48
21
  files:
49
22
  - ".codeclimate.yml"
50
23
  - ".coveralls.yml"
24
+ - ".github/workflows/ruby.yml"
51
25
  - ".gitignore"
52
26
  - ".overcommit.yml"
27
+ - ".rspec"
53
28
  - ".rubocop.yml"
54
- - ".travis.yml"
29
+ - CHANGELOG.md
55
30
  - Gemfile
56
31
  - Gemfile.lock
57
32
  - LICENSE
58
33
  - README.md
59
34
  - Rakefile
60
35
  - bin/console
61
- - bin/random_name_generator
36
+ - bin/run
62
37
  - bin/setup
63
38
  - config.reek
39
+ - exe/random_name_generator
40
+ - lib/languages/demonic.txt
41
+ - lib/languages/elven-ru.txt
42
+ - lib/languages/elven.txt
43
+ - lib/languages/experimental/curse.txt
44
+ - lib/languages/experimental/demonic.txt
45
+ - lib/languages/fantasy-ru.txt
46
+ - lib/languages/fantasy.txt
47
+ - lib/languages/goblin-ru.txt
48
+ - lib/languages/goblin.txt
49
+ - lib/languages/roman-ru.txt
50
+ - lib/languages/roman.txt
64
51
  - lib/random_name_generator.rb
65
- - lib/random_name_generator/languages/demonic.txt
66
- - lib/random_name_generator/languages/elven.txt
67
- - lib/random_name_generator/languages/fantasy.txt
68
- - lib/random_name_generator/languages/goblin.txt
69
- - lib/random_name_generator/languages/roman.txt
70
- - lib/random_name_generator/random_name_generator.rb
71
- - lib/random_name_generator/rng_syllable.rb
52
+ - lib/random_name_generator/syllable.rb
53
+ - lib/random_name_generator/version.rb
72
54
  - random_name_generator.gemspec
73
55
  homepage: https://github.com/folkengine/random_name_generator
74
56
  licenses:
75
- - GPL-3.0
76
- metadata: {}
77
- post_install_message:
57
+ - LGPL-3.0
58
+ metadata:
59
+ homepage_uri: https://github.com/folkengine/random_name_generator
60
+ source_code_uri: https://github.com/folkengine/random_name_generator
61
+ changelog_uri: https://github.com/folkengine/random_name_generator/CHANGELOG.md
62
+ post_install_message:
78
63
  rdoc_options: []
79
64
  require_paths:
80
65
  - lib
@@ -82,16 +67,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
82
67
  requirements:
83
68
  - - ">="
84
69
  - !ruby/object:Gem::Version
85
- version: '2.2'
70
+ version: 2.5.0
86
71
  required_rubygems_version: !ruby/object:Gem::Requirement
87
72
  requirements:
88
73
  - - ">="
89
74
  - !ruby/object:Gem::Version
90
75
  version: '0'
91
76
  requirements: []
92
- rubyforge_project:
93
- rubygems_version: 2.7.7
94
- signing_key:
77
+ rubygems_version: 3.2.3
78
+ signing_key:
95
79
  specification_version: 4
96
80
  summary: Random Name Generator
97
81
  test_files: []
data/.travis.yml DELETED
@@ -1,4 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - "2.3.1"
4
- - "2.5.1"
@@ -1,27 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'slop'
4
- require_relative '../lib/random_name_generator'
5
-
6
- lang = RandomNameGenerator::FANTASY
7
-
8
- opts = Slop.parse do |o|
9
- o.bool '-e', '--elven', 'Use Elven eyllable file'
10
- o.bool '-g', '--goblin', 'Use Goblin eyllable file'
11
- o.bool '-r', '--roman', 'Use Roman eyllable file'
12
- o.bool '-f', '--flipmode', 'Flip mode in effect'
13
- o.bool '-?', '--help', 'How to'
14
- end
15
-
16
- lang = RandomNameGenerator::ELVEN if opts.elven?
17
- lang = RandomNameGenerator::GOBLIN if opts.goblin?
18
- lang = RandomNameGenerator::ROMAN if opts.roman?
19
-
20
- if opts.flipmode?
21
- puts "#{RandomNameGenerator.flip_mode.compose} #{RandomNameGenerator.flip_mode.compose}"
22
- elsif opts.help?
23
- puts opts
24
- else
25
- rndgen = RandomNameGenerator.new(lang)
26
- puts "#{rndgen.compose} #{rndgen.compose}"
27
- end
@@ -1,107 +0,0 @@
1
- require_relative 'rng_syllable'
2
-
3
- # RandomNameGenerator:
4
- #
5
- # Examples
6
- #
7
- # rng = RandomNameGenerator.new(RandomNameGenerator::GOBLIN)
8
- # puts rng.compose(3)
9
- #
10
- # By default RandomNameGenerator uses the Fantasy syllable file and creates a name with between 2 and 5 syllables.
11
- #
12
- # rng = RandomNameGenerator.new
13
- # puts rng.compose
14
- #
15
- # :reek:TooManyInstanceVariables
16
- # :reek:TooManyStatements
17
- class RandomNameGenerator
18
- dirname = File.dirname(__FILE__)
19
-
20
- ELVEN = File.new("#{dirname}/languages/elven.txt")
21
- FANTASY = File.new("#{dirname}/languages/fantasy.txt")
22
- GOBLIN = File.new("#{dirname}/languages/goblin.txt")
23
- ROMAN = File.new("#{dirname}/languages/roman.txt")
24
-
25
- attr_reader :pre, :pre_syllables, :sur_syllables, :mid_syllables
26
-
27
- def initialize(filename = RandomNameGenerator::FANTASY, random: Random.new)
28
- @pre = nil
29
- @file = File.new(filename)
30
- @rnd = random
31
- @pre_syllables = []
32
- @sur_syllables = []
33
- @mid_syllables = []
34
-
35
- refresh
36
- end
37
-
38
- # Public: Static factory method that instantiates a RandomNameGenerator in a random language.
39
- def self.flip_mode
40
- langs = [RandomNameGenerator::FANTASY,
41
- RandomNameGenerator::ELVEN,
42
- RandomNameGenerator::GOBLIN,
43
- RandomNameGenerator::ROMAN]
44
- new(langs.sample)
45
- end
46
-
47
- def compose(count = RandomNameGenerator.pick_number_of_syllables)
48
- @pre = pre_syllables.sample
49
- return @pre.to_s.capitalize if count < 2
50
-
51
- name = determine_middle_syllables(count - 2, pre)
52
- name << determine_last_syllable(name.last)
53
- name.map(&:to_s).join.capitalize
54
- end
55
-
56
- def self.pick_number_of_syllables
57
- [2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 5].sample
58
- end
59
-
60
- def to_s
61
- "RandomNameGenerator (#{@file.path})"
62
- end
63
-
64
- private
65
-
66
- def determine_middle_syllables(count, pre)
67
- determine_next_syllables(count, pre, @mid_syllables)
68
- end
69
-
70
- def determine_last_syllable(next_to_last_syllable)
71
- determine_next_syllable(next_to_last_syllable, @sur_syllables)
72
- end
73
-
74
- def determine_next_syllables(count, pre, syllables)
75
- name = Array(pre)
76
- return name if count < 1
77
-
78
- next_syllable = pre
79
- count.times do
80
- next_syllable = determine_next_syllable(next_syllable, syllables)
81
- name << next_syllable
82
- end
83
- name
84
- end
85
-
86
- def determine_next_syllable(this_syllable, sampler)
87
- next_syllable = ''
88
- loop do
89
- next_syllable = sampler.sample(random: @rnd)
90
- break unless this_syllable.incompatible?(next_syllable)
91
- end
92
- next_syllable
93
- end
94
-
95
- def refresh
96
- @file.readlines.each do |line|
97
- syllable = RNGSyllable.new(line) unless line.empty?
98
- if syllable.prefix?
99
- @pre_syllables.push(syllable)
100
- elsif syllable.suffix?
101
- @sur_syllables.push(syllable)
102
- else
103
- @mid_syllables.push(syllable)
104
- end
105
- end
106
- end
107
- end
@@ -1,175 +0,0 @@
1
- # RNGSyllable: Class for managing properties of individual syllables with in language name file. Each line within a file
2
- # translates into a syllable object. The reason behind this class is to take over most of the complexity of parsing each
3
- # syllable, greatly simplifying the work done by RandomNameGenerator. This code is not meant to be called directly as a
4
- # part of standard usage.
5
- #
6
- # Examples
7
- #
8
- # syllable = RNGSyllable.new('-foo +c')
9
- #
10
- # This creates a foo syllable object that needs to be the first syllable and followed by a constant.
11
- #
12
- # For testing purposes, passing in another RNGSyllable object will create a clone:
13
- #
14
- # syllable_clone = RNGSyllable.new(syllable)
15
- #
16
- # SYLLABLE CLASSIFICATION:
17
- # Name is usually composed from 3 different class of syllables, which include prefix, middle part and suffix.
18
- # To declare syllable as a prefix in the file, insert "-" as a first character of the line.
19
- # To declare syllable as a suffix in the file, insert "+" as a first character of the line.
20
- # everything else is read as a middle part.
21
- #
22
- # NUMBER OF SYLLABLES:
23
- # Names may have any positive number of syllables. In case of 2 syllables, name will be composed from prefix and suffix.
24
- # In case of 1 syllable, name will be chosen from amongst the prefixes.
25
- # In case of 3 and more syllables, name will begin with prefix, is filled with middle parts and ended with suffix.
26
- #
27
- # ASSIGNING RULES:
28
- # I included a way to set 4 kind of rules for every syllable. To add rules to the syllables, write them right after the
29
- # syllable and SEPARATE WITH WHITESPACE. (example: "aad +v -c"). The order of rules is not important.
30
- #
31
- # RULES:
32
- # 1) +v means that next syllable must definitely start with a vocal.
33
- # 2) +c means that next syllable must definitely start with a consonant.
34
- # 3) -v means that this syllable can only be added to another syllable, that ends with a vocal.
35
- # 4) -c means that this syllable can only be added to another syllable, that ends with a consonant.
36
- #
37
- # :reek:TooManyMethods
38
- # :reek:TooManyInstanceVariables
39
- class RNGSyllable
40
- attr_reader :raw, :syllable, :next_syllable_requirement, :previous_syllable_requirement
41
-
42
- VOWELS ||= %w[i y ɨ ʉ ɯ u ɪ ʏ ʊ ɯ ʊ e ø ɘ ɵ ɤ o ø ə ɵ ɤ o ɛ œ ɜ ɞ ʌ ɔ æ ɐ ɞ a ɶ ä ɒ ɑ].freeze
43
- CONSONANTS ||= %w[b ɓ ʙ β c d ɗ ɖ ð f g h j k l ł m ɱ n ɳ p q r s t v w x y z].freeze
44
-
45
- def initialize(args)
46
- @raw = args
47
- @syllable = ''
48
- @is_prefix = false
49
- @is_suffix = false
50
- @next_syllable_requirement = :letter
51
- @previous_syllable_requirement = :letter
52
-
53
- if args.is_a?(RNGSyllable) then
54
- parse_args(args.raw)
55
- else
56
- parse_args(args)
57
- end
58
- end
59
-
60
- def incompatible?(next_syllable)
61
- (next_incompatible?(next_syllable) || previous_incompatible?(next_syllable))
62
- end
63
-
64
- def compatible?(next_syllable)
65
- !incompatible?(next_syllable)
66
- end
67
-
68
- def prefix?
69
- @is_prefix
70
- end
71
-
72
- def suffix?
73
- @is_suffix
74
- end
75
-
76
- def consonant_first?
77
- CONSONANTS.include?(syllable[0])
78
- end
79
-
80
- def vowel_first?
81
- VOWELS.include?(syllable[0])
82
- end
83
-
84
- def consonant_last?
85
- CONSONANTS.include?(syllable[-1])
86
- end
87
-
88
- def vowel_last?
89
- VOWELS.include?(syllable[-1])
90
- end
91
-
92
- def next_syllable_universal?
93
- @next_syllable_requirement == :letter
94
- end
95
-
96
- def next_syllable_must_start_with_vowel?
97
- @next_syllable_requirement == :vowel
98
- end
99
-
100
- def next_syllable_must_start_with_consonant?
101
- @next_syllable_requirement == :consonant
102
- end
103
-
104
- def previous_syllable_universal?
105
- @previous_syllable_requirement == :letter
106
- end
107
-
108
- def previous_syllable_must_end_with_vowel?
109
- @previous_syllable_requirement == :vowel
110
- end
111
-
112
- def previous_syllable_must_end_with_consonant?
113
- @previous_syllable_requirement == :consonant
114
- end
115
-
116
- def to_s
117
- @syllable
118
- end
119
-
120
- def to_str
121
- @syllable
122
- end
123
-
124
- private
125
-
126
- # :reek:FeatureEnvy
127
- def parse_args(args)
128
- args = args.to_s.strip.downcase.split(' ')
129
- parse_syllable(args[0])
130
- parse_flags(args[1..-1])
131
- end
132
-
133
- def parse_syllable(syll)
134
- raise ArgumentError 'Empty String is not allowed.' if syll.empty?
135
-
136
- captures = /([+-]?)(.+)/.match(syll).captures
137
- parse_prefix(captures[0])
138
- @syllable = captures[1]
139
- end
140
-
141
- def parse_prefix(prefix)
142
- if prefix.eql?('-')
143
- @is_prefix = true
144
- elsif prefix.eql?('+')
145
- @is_suffix = true
146
- end
147
- end
148
-
149
- def parse_flags(flags)
150
- if flags.include?('+v')
151
- @next_syllable_requirement = :vowel
152
- elsif flags.include?('+c')
153
- @next_syllable_requirement = :consonant
154
- end
155
- if flags.include?('-v')
156
- @previous_syllable_requirement = :vowel
157
- elsif flags.include?('-c')
158
- @previous_syllable_requirement = :consonant
159
- end
160
- end
161
-
162
- def next_incompatible?(next_syllable)
163
- vnc = (next_syllable_must_start_with_vowel? && next_syllable.consonant_first?)
164
- cnv = (next_syllable_must_start_with_consonant? && next_syllable.vowel_first?)
165
-
166
- (vnc || cnv)
167
- end
168
-
169
- def previous_incompatible?(next_syllable)
170
- vlc = (vowel_last? && next_syllable.previous_syllable_must_end_with_consonant?)
171
- clv = (consonant_last? && next_syllable.previous_syllable_must_end_with_vowel?)
172
-
173
- (vlc || clv)
174
- end
175
- end