unique_names_generator 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9c3735cb47c574108e11dde60274f4d2013c0b281fd2bdf08cecc595e9acd2ac
4
- data.tar.gz: 9ccbf1f0f972547de8baabe8675b1a1540ace3a4a24caf3dd88728d86650ba52
3
+ metadata.gz: 65b327e97d35d0196016feff3a0f7814f4b398405c58a6a398beb835a364a74d
4
+ data.tar.gz: ad729f68a508030690fcf38c56bd899bce70e372886a113995ef63ca8e896751
5
5
  SHA512:
6
- metadata.gz: c049f7832bc38164a17215c3ddaf830b534ec642b25494045f89c39ccb08d7c639a39af7fd061e988173bc7c5190eb8a634f2ebaed562b286d80411cbe77cdb9
7
- data.tar.gz: f9a0be92fb3dbbe8a48bc588b202217d97edcd299f21699a26d7712d9b5129cb8dd0a535ffb7c4f0976bc0377f983f4e047fb9a597800131157262efc623de92
6
+ metadata.gz: '038bb93ba4b7bc097fe528575bc6ba4debb7810b8f2c0d204cdd2a08bfaf82cd888ee7972afb14ed34d09f7fecde9f62b3e0b7ef18246720f67b59e24e69fcb4'
7
+ data.tar.gz: 4c4aa71be2f0f243ebf30f1184d41842c2627380271428463c53120bf2676e49d6539f492b948d5908d99e3c1be3f9f6e029fe05f4118e7a05e014777edecedb
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ *.gem
2
+ .DS_Store
3
+ .yardoc
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- unique_names_generator (0.1.0)
4
+ unique_names_generator (0.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -12,7 +12,7 @@ by adding `unique_names_generator` to your list of gemfile dependencies:
12
12
  Add this line to your application's Gemfile:
13
13
 
14
14
  ```
15
- gem 'unique_names_generator', "~> 0.1.0"
15
+ gem 'unique_names_generator', "~> 0.1.1"
16
16
  ```
17
17
 
18
18
  And then execute:
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module UniqueNamesGenerator
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
@@ -30,163 +30,146 @@ module UniqueNamesGenerator
30
30
  generate_name(dictionaries)
31
31
  end
32
32
 
33
- def match_word_list(dictionary)
34
- module_name = camelize_dictionary(dictionary)
35
- begin
36
- dictionary = Dictionaries.const_get(module_name)
37
- dictionary.list_all
38
- rescue NameError
39
- raise_invalid_dictionary(dictionary)
33
+ class << self
34
+ private
35
+
36
+ def match_word_list(dictionary)
37
+ module_name = camelize_dictionary(dictionary)
38
+ begin
39
+ dictionary = Dictionaries.const_get(module_name)
40
+ dictionary.list_all
41
+ rescue NameError
42
+ raise_invalid_dictionary(dictionary)
43
+ end
40
44
  end
41
- end
42
45
 
43
- def word_list(dictionary)
44
- case dictionary
45
- when Array
46
- dictionary if dictionary.all? { |item| item.is_a?(String) }
47
- when Symbol
48
- match_word_list(dictionary)
49
- else
50
- raise ArgumentError, 'Dictionary contains invalid dictionary type'
46
+ def word_list(dictionary)
47
+ case dictionary
48
+ when Array
49
+ dictionary if dictionary.all? { |item| item.is_a?(String) }
50
+ when Symbol
51
+ match_word_list(dictionary)
52
+ else
53
+ raise ArgumentError, 'Dictionary contains invalid dictionary type'
54
+ end
51
55
  end
52
- end
53
56
 
54
- def random_seeded_float
55
- seed_value = Seed.generate_seed(@seed)
57
+ def random_seeded_float
58
+ seed_value = Seed.generate_seed(@seed)
56
59
 
57
- prng = @seed.nil? ? Random.new : Random.new(seed_value)
58
- prng.rand
59
- end
60
-
61
- def map_dictionaries(dictionaries)
62
- dictionaries.map { |dictionary| word_list(dictionary) }
63
- end
60
+ prng = @seed.nil? ? Random.new : Random.new(seed_value)
61
+ prng.rand
62
+ end
64
63
 
65
- def split_with_separator(word)
66
- if @separator.nil?
67
- word.split(/(?=[A-Z])/)
68
- else
69
- word.split(@separator)
64
+ def map_dictionaries(dictionaries)
65
+ dictionaries.map { |dictionary| word_list(dictionary) }
70
66
  end
71
- end
72
67
 
73
- def format_parts(parts)
74
- parts.map do |part|
75
- if part.match?(/[^a-zA-Z]/) && @style == :capital
76
- # Preserve original capitalization for parts with non-letter characters
77
- part
68
+ def split_with_separator(word)
69
+ if @separator.nil?
70
+ word.split(/(?=[A-Z])/)
78
71
  else
79
- format_word(part, @style)
72
+ word.split(@separator)
80
73
  end
81
- end.join(@separator)
82
- end
74
+ end
83
75
 
84
- def format_multi_word(word, original_word)
85
- if original_word.include?(' ') || original_word.include?('-')
86
- parts = split_with_separator(word)
87
- format_parts(parts)
88
- else
89
- format_word(word, @style)
76
+ def format_parts(parts)
77
+ parts.map do |part|
78
+ if part.match?(/[^a-zA-Z]/) && @style == :capital
79
+ # Preserve original capitalization for parts with non-letter characters
80
+ part
81
+ else
82
+ format_word(part, @style)
83
+ end
84
+ end.join(@separator)
85
+ end
86
+
87
+ def format_multi_word(word, original_word)
88
+ if original_word.include?(' ') || original_word.include?('-')
89
+ parts = split_with_separator(word)
90
+ format_parts(parts)
91
+ else
92
+ format_word(word, @style)
93
+ end
90
94
  end
91
- end
92
95
 
93
- def generate_name(dictionaries)
94
- if @creativity.nil? || @creativity.zero?
95
- generate_name_original(dictionaries)
96
- else
97
- generate_name_creatively(dictionaries)
96
+ def generate_name(dictionaries)
97
+ if @creativity.nil? || @creativity.zero?
98
+ generate_name_original(dictionaries)
99
+ else
100
+ generate_name_creatively(dictionaries)
101
+ end
98
102
  end
99
- end
100
103
 
101
- def generate_name_original(dictionaries)
102
- map_dictionaries(dictionaries).reduce(nil) do |acc, x|
103
- rnd = (random_seeded_float * x.length).floor
104
- original_word = x[rnd]
104
+ def generate_name_original(dictionaries)
105
+ map_dictionaries(dictionaries).reduce(nil) do |acc, x|
106
+ rnd = (random_seeded_float * x.length).floor
107
+ original_word = x[rnd]
105
108
 
106
- output_word(acc, original_word)
109
+ output_word(acc, original_word)
110
+ end
107
111
  end
108
- end
109
112
 
110
- def generate_name_creatively(dictionaries)
111
- word_lists = map_dictionaries(dictionaries)
113
+ def generate_name_creatively(dictionaries)
114
+ word_lists = map_dictionaries(dictionaries)
112
115
 
113
- word_lists.each_with_index.reduce(nil) do |acc, (word_list, index)|
114
- creativity = calculate_creativity(index)
115
- rnd = (random_seeded_float * word_list.length * creativity).floor
116
- original_word = word_list[rnd % word_list.length] # Ensure we don't go out of bounds
116
+ word_lists.each_with_index.reduce(nil) do |acc, (word_list, index)|
117
+ creativity = calculate_creativity(index)
118
+ rnd = (random_seeded_float * word_list.length * creativity).floor
119
+ original_word = word_list[rnd % word_list.length] # Ensure we don't go out of bounds
117
120
 
118
- output_word(acc, original_word)
121
+ output_word(acc, original_word)
122
+ end
119
123
  end
120
- end
121
124
 
122
- def output_word(acc, original_word)
123
- word = format_with_separator(original_word)
124
- word = format_multi_word(word, original_word)
125
+ def output_word(acc, original_word)
126
+ word = format_with_separator(original_word)
127
+ word = format_multi_word(word, original_word)
125
128
 
126
- if acc
127
- "#{acc}#{@separator}#{word}"
128
- else
129
- word
129
+ if acc
130
+ "#{acc}#{@separator}#{word}"
131
+ else
132
+ word
133
+ end
130
134
  end
131
- end
132
135
 
133
- def calculate_creativity(index)
134
- if index.zero?
135
- @creativity # Base creativity for the first dictionary
136
- else
137
- @creativity * (2 + index * 0.5) # Increase creativity for subsequent dictionaries
136
+ def calculate_creativity(index)
137
+ if index.zero?
138
+ @creativity # Base creativity for the first dictionary
139
+ else
140
+ @creativity * (2 + index * 0.5) # Increase creativity for subsequent dictionaries
141
+ end
138
142
  end
139
- end
140
143
 
141
- def camelize_dictionary(dictionary)
142
- dictionary.to_s.split('_').map(&:capitalize).join
143
- end
144
+ def camelize_dictionary(dictionary)
145
+ dictionary.to_s.split('_').map(&:capitalize).join
146
+ end
144
147
 
145
- def raise_invalid_dictionary(dictionary)
146
- raise ArgumentError, "Invalid dictionary: #{dictionary}"
147
- end
148
+ def raise_invalid_dictionary(dictionary)
149
+ raise ArgumentError, "Invalid dictionary: #{dictionary}"
150
+ end
148
151
 
149
- def format_with_separator(word)
150
- if @separator.nil?
151
- # If separator is empty, just remove spaces without changing case
152
- word.gsub(/\s+/, '')
153
- else
154
- # If there's a separator, use it to replace spaces
155
- word.gsub(/\s+/, @separator)
152
+ def format_with_separator(word)
153
+ if @separator.nil?
154
+ # If separator is empty, just remove spaces without changing case
155
+ word.gsub(/\s+/, '')
156
+ else
157
+ # If there's a separator, use it to replace spaces
158
+ word.gsub(/\s+/, @separator)
159
+ end
156
160
  end
157
- end
158
161
 
159
- def format_word(word, style)
160
- case style
161
- when :lowercase
162
- word.downcase
163
- when :uppercase
164
- word.upcase
165
- when :capital
166
- word.capitalize
167
- else
168
- word
162
+ def format_word(word, style)
163
+ case style
164
+ when :lowercase
165
+ word.downcase
166
+ when :uppercase
167
+ word.upcase
168
+ when :capital
169
+ word.capitalize
170
+ else
171
+ word
172
+ end
169
173
  end
170
174
  end
171
-
172
- private_class_method(
173
- *%i[
174
- generate_name
175
- match_word_list
176
- word_list
177
- random_seeded_float
178
- map_dictionaries
179
- camelize_dictionary
180
- raise_invalid_dictionary
181
- format_with_separator
182
- format_multi_word
183
- format_parts
184
- format_word
185
- split_with_separator
186
- generate_name_original
187
- generate_name_creatively
188
- calculate_creativity
189
- output_word
190
- ]
191
- )
192
175
  end
@@ -15,7 +15,8 @@ Gem::Specification.new do |s|
15
15
  s.email = 'jongirard03@gmail.com'
16
16
  s.homepage = 'https://github.com/jongirard/unique_names_generator_ruby'
17
17
  s.metadata = { 'homepage_uri' => 'https://github.com/jongirard/unique_names_generator_ruby',
18
- 'source_code_uri' => 'https://github.com/jongirard/unique_names_generator_ruby' }
18
+ 'source_code_uri' => 'https://github.com/jongirard/unique_names_generator_ruby',
19
+ 'documentation_uri' => 'https://jongirard.github.io/unique_names_generator_ruby' }
19
20
  s.require_paths = ['lib']
20
21
  s.license = 'MIT'
21
22
  s.files = Dir.chdir(File.expand_path(__dir__)) do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unique_names_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Girard
@@ -34,6 +34,7 @@ extensions: []
34
34
  extra_rdoc_files: []
35
35
  files:
36
36
  - ".github/workflows/ruby.yml"
37
+ - ".gitignore"
37
38
  - ".pryrc"
38
39
  - ".rspec"
39
40
  - ".rubocop.yml"
@@ -59,6 +60,7 @@ licenses:
59
60
  metadata:
60
61
  homepage_uri: https://github.com/jongirard/unique_names_generator_ruby
61
62
  source_code_uri: https://github.com/jongirard/unique_names_generator_ruby
63
+ documentation_uri: https://jongirard.github.io/unique_names_generator_ruby
62
64
  post_install_message:
63
65
  rdoc_options: []
64
66
  require_paths: