random_name_generator 1.0.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
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.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - folkengine
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-24 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-03-29 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.1.5
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.5.1
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,5 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - "2.1.5"
4
- - "2.2.0"
5
- - "2.3.0"
@@ -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,103 +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
- class RandomNameGenerator
16
- dirname = File.dirname(__FILE__)
17
-
18
- ELVEN = File.new("#{dirname}/languages/elven.txt")
19
- FANTASY = File.new("#{dirname}/languages/fantasy.txt")
20
- GOBLIN = File.new("#{dirname}/languages/goblin.txt")
21
- ROMAN = File.new("#{dirname}/languages/roman.txt")
22
-
23
- attr_reader :pre, :pre_syllables, :sur_syllables, :mid_syllables
24
-
25
- def initialize(filename = RandomNameGenerator::FANTASY, random: Random.new)
26
- @file = File.new(filename)
27
- @rnd = random
28
- @pre_syllables = []
29
- @sur_syllables = []
30
- @mid_syllables = []
31
-
32
- refresh
33
- end
34
-
35
- # Public: Static factory method that instantiates a RandomNameGenerator in a random language.
36
- def self.flip_mode
37
- langs = [RandomNameGenerator::FANTASY,
38
- RandomNameGenerator::ELVEN,
39
- RandomNameGenerator::GOBLIN,
40
- RandomNameGenerator::ROMAN]
41
- new(langs.sample)
42
- end
43
-
44
- def compose(count = RandomNameGenerator.pick_number_of_syllables)
45
- @pre = pre_syllables.sample
46
- return @pre.to_s.capitalize if count < 2
47
-
48
- name = determine_middle_syllables(count - 2, pre)
49
- name << determine_last_syllable(name.last)
50
- name.map(&:to_s).join.capitalize
51
- end
52
-
53
- def self.pick_number_of_syllables
54
- [2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 5].sample
55
- end
56
-
57
- def to_s
58
- "NameGenerator (#{@file.path})"
59
- end
60
-
61
- private
62
-
63
- def determine_middle_syllables(count, pre)
64
- determine_next_syllables(count, pre, @mid_syllables)
65
- end
66
-
67
- def determine_last_syllable(next_to_last_syllable)
68
- determine_next_syllable(next_to_last_syllable, @sur_syllables)
69
- end
70
-
71
- def determine_next_syllables(count, pre, syllables)
72
- name = Array(pre)
73
- return name if count < 1
74
- next_syllable = pre
75
- count.times do
76
- next_syllable = determine_next_syllable(next_syllable, syllables)
77
- name << next_syllable
78
- end
79
- name
80
- end
81
-
82
- def determine_next_syllable(this_syllable, sampler)
83
- next_syllable = ''
84
- loop do
85
- next_syllable = sampler.sample(random: @rnd)
86
- break unless this_syllable.incompatible?(next_syllable)
87
- end
88
- next_syllable
89
- end
90
-
91
- def refresh
92
- @file.readlines.each do |line|
93
- syllable = RNGSyllable.new(line) unless line.empty?
94
- if syllable.prefix?
95
- @pre_syllables.push(syllable)
96
- elsif syllable.suffix?
97
- @sur_syllables.push(syllable)
98
- else
99
- @mid_syllables.push(syllable)
100
- end
101
- end
102
- end
103
- end
@@ -1,170 +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
- class RNGSyllable
37
- attr_reader :raw, :syllable, :next_syllable_requirement, :previous_syllable_requirement
38
-
39
- VOWELS ||= %w(i y ɨ ʉ ɯ u ɪ ʏ ʊ ɯ ʊ e ø ɘ ɵ ɤ o ø ə ɵ ɤ o ɛ œ ɜ ɞ ʌ ɔ æ ɐ ɞ a ɶ ä ɒ ɑ).freeze
40
- CONSONANTS ||= %w(b ɓ ʙ β c d ɗ ɖ ð f g h j k l ł m ɱ n ɳ p q r s t v w x y z).freeze
41
-
42
- def initialize(args)
43
- @raw = args
44
- @is_prefix = false
45
- @is_suffix = false
46
- @next_syllable_requirement = :letter
47
- @previous_syllable_requirement = :letter
48
-
49
- if args.is_a?(RNGSyllable) then
50
- parse_args(args.raw)
51
- else
52
- parse_args(args)
53
- end
54
- end
55
-
56
- def incompatible?(next_syllable)
57
- (next_incompatible?(next_syllable) || previous_incompatible?(next_syllable))
58
- end
59
-
60
- def compatible?(next_syllable)
61
- !incompatible?(next_syllable)
62
- end
63
-
64
- def prefix?
65
- @is_prefix
66
- end
67
-
68
- def suffix?
69
- @is_suffix
70
- end
71
-
72
- def consonant_first?
73
- CONSONANTS.include?(syllable[0])
74
- end
75
-
76
- def vowel_first?
77
- VOWELS.include?(syllable[0])
78
- end
79
-
80
- def consonant_last?
81
- CONSONANTS.include?(syllable[-1])
82
- end
83
-
84
- def vowel_last?
85
- VOWELS.include?(syllable[-1])
86
- end
87
-
88
- def next_syllable_universal?
89
- @next_syllable_requirement == :letter
90
- end
91
-
92
- def next_syllable_must_start_with_vowel?
93
- @next_syllable_requirement == :vowel
94
- end
95
-
96
- def next_syllable_must_start_with_consonant?
97
- @next_syllable_requirement == :consonant
98
- end
99
-
100
- def previous_syllable_universal?
101
- @previous_syllable_requirement == :letter
102
- end
103
-
104
- def previous_syllable_must_end_with_vowel?
105
- @previous_syllable_requirement == :vowel
106
- end
107
-
108
- def previous_syllable_must_end_with_consonant?
109
- @previous_syllable_requirement == :consonant
110
- end
111
-
112
- def to_s
113
- @syllable
114
- end
115
-
116
- def to_str
117
- @syllable
118
- end
119
-
120
- private
121
-
122
- def parse_args(args)
123
- args = raw.to_s.strip.downcase.split(' ')
124
- parse_syllable(args[0])
125
- parse_flags(args[1..-1])
126
- end
127
-
128
- def parse_syllable(syll)
129
- raise ArgumentError 'Empty String is not allowed.' if syll.empty?
130
-
131
- captures = /([+-]?)(.+)/.match(syll).captures
132
- parse_prefix(captures[0])
133
- @syllable = captures[1]
134
- end
135
-
136
- def parse_prefix(prefix)
137
- if prefix.eql?('-')
138
- @is_prefix = true
139
- elsif prefix.eql?('+')
140
- @is_suffix = true
141
- end
142
- end
143
-
144
- def parse_flags(flags)
145
- if flags.include?('+v')
146
- @next_syllable_requirement = :vowel
147
- elsif flags.include?('+c')
148
- @next_syllable_requirement = :consonant
149
- end
150
- if flags.include?('-v')
151
- @previous_syllable_requirement = :vowel
152
- elsif flags.include?('-c')
153
- @previous_syllable_requirement = :consonant
154
- end
155
- end
156
-
157
- def next_incompatible?(next_syllable)
158
- vnc = (next_syllable_must_start_with_vowel? && next_syllable.consonant_first?)
159
- cnv = (next_syllable_must_start_with_consonant? && next_syllable.vowel_first?)
160
-
161
- (vnc || cnv)
162
- end
163
-
164
- def previous_incompatible?(next_syllable)
165
- vlc = (vowel_last? && next_syllable.previous_syllable_must_end_with_consonant?)
166
- clv = (consonant_last? && next_syllable.previous_syllable_must_end_with_vowel?)
167
-
168
- (vlc || clv)
169
- end
170
- end