unique_names_generator 0.1.2 → 0.2.0

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: 65b327e97d35d0196016feff3a0f7814f4b398405c58a6a398beb835a364a74d
4
- data.tar.gz: ad729f68a508030690fcf38c56bd899bce70e372886a113995ef63ca8e896751
3
+ metadata.gz: f9773f651a33cab35886353896b6138a9e1df7d1bbecf1c0573be4da2567eda2
4
+ data.tar.gz: 3dac60147e276911a7c17c505afe95e305800e6aeb897797d925a1844fe2d57d
5
5
  SHA512:
6
- metadata.gz: '038bb93ba4b7bc097fe528575bc6ba4debb7810b8f2c0d204cdd2a08bfaf82cd888ee7972afb14ed34d09f7fecde9f62b3e0b7ef18246720f67b59e24e69fcb4'
7
- data.tar.gz: 4c4aa71be2f0f243ebf30f1184d41842c2627380271428463c53120bf2676e49d6539f492b948d5908d99e3c1be3f9f6e029fe05f4118e7a05e014777edecedb
6
+ metadata.gz: 61b362f06916f9f08ab89e91421a4ee0c482433a4d6c9843645d6b02feab966d6197383993425fbf8b1740d211ea53ef149e9d632df0669172755a57be977a32
7
+ data.tar.gz: 0534cb36f75cc5e04fe72c9cdae7e05199880d0e06f1b3e0d7f6f797644f882980356232a79a2c06bb0a54da29ffbdc67f07e22ee6b2e96b9d51548e0aae78e5
data/.rubocop.yml CHANGED
@@ -27,5 +27,12 @@ Style/SymbolArray:
27
27
  Exclude:
28
28
  - 'spec/**/*'
29
29
 
30
+ Layout/SpaceInsideBlockBraces:
31
+ Exclude:
32
+ - 'spec/**/*'
33
+
30
34
  Style/NumericPredicate:
31
- Enabled: false
35
+ Enabled: false
36
+
37
+ Metrics/ClassLength:
38
+ Max: 150
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- unique_names_generator (0.1.1)
4
+ unique_names_generator (0.2.0)
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.1"
15
+ gem 'unique_names_generator', '~> 0.2.0'
16
16
  ```
17
17
 
18
18
  And then execute:
@@ -29,16 +29,19 @@ $ gem install unique_names_generator
29
29
 
30
30
  ## Usage
31
31
 
32
- In a nutshell, you can begin generating randon names with UniqueNamesGenerator by simply specifying an array of one or more dictionaries via `UniqueNamesGenerator.generate`. Available dictionary types are `[:adjectives, :animals, :colors, :languages, :names, :numbers, :star_wars]`.
32
+ In a nutshell, you can begin generating random names with UniqueNamesGenerator by simply creating a Generator instance and specifying an array of one or more dictionaries. Available dictionary types are `[:adjectives, :animals, :colors, :languages, :names, :numbers, :star_wars]`.
33
33
 
34
34
  ```ruby
35
- UniqueNamesGenerator.generate([:adjectives, :animals])
35
+ generator = UniqueNamesGenerator::Generator.new([:adjectives, :animals])
36
+ generator.generate
36
37
  # => Generates ex: "dramatic_limpet"
37
38
 
38
- UniqueNamesGenerator.generate([:adjectives, :colors, :animals])
39
+ generator = UniqueNamesGenerator::Generator.new([:adjectives, :colors, :animals])
40
+ generator.generate
39
41
  # => Generates ex: "tremendous_brown_cat"
40
42
 
41
- UniqueNamesGenerator.generate([:adjectives, :names, :numbers])
43
+ generator = UniqueNamesGenerator::Generator.new([:adjectives, :names, :numbers])
44
+ generator.generate
42
45
  # => Generates ex: "doubtful_wanda_979"
43
46
  ```
44
47
 
@@ -46,7 +49,9 @@ To use custom dictionaries, simply include your array of strings as part of the
46
49
 
47
50
  ```ruby
48
51
  drinks = ['Sprite', 'Coca-Cola', 'Juice', 'Tea']
49
- UniqueNamesGenerator.generate([:colors, drinks])
52
+
53
+ generator = UniqueNamesGenerator::Generator.new([:colors, drinks])
54
+ generator.generate
50
55
  # => Generates ex: "cyan_sprite"
51
56
  ```
52
57
 
@@ -55,17 +60,20 @@ UniqueNamesGenerator.generate([:colors, drinks])
55
60
  UniqueNamesGenerator can be used with either the default provided config (`separator: '_', style: :lowercase, creativity: 0`) or by specifying any of your own configuration options for seeding, seperator, style and creativity.
56
61
 
57
62
  #### More details on possible options
58
-
59
- - **Separator options**: Any ASCII character string such as underscore, dash or blank space. `nil` for no space.
63
+ - **Dictionaries**: [Array<Symbol, Array<String>>] List of dictionaries to use for name generation. Can be symbols referring to built-in dictionaries or custom arrays of strings.
64
+ - **Separator**: [String] Character(s) used to join words in the generated name. Default: '_'. `nil` can be used for no space.
60
65
  - ex: '_', '-', ' ' or `nil` for no space.
61
- - **Style options**: Atom, one of `:lowercase`, `:uppercase`, `:capital`.
62
- - **Creativity options**: An integer or float between 1 and 10.
66
+ - **Style**: [Symbol] Capitalization style for generated names.
67
+ - Options: `:lowercase`, `:uppercase`, `:capital`. Default: `:lowercase`
68
+ - **Creativity**: [Integer] Level of creativity in name generation, affecting word selection. Must be between 0 and 10. A Float value can also be used. Default: 0
63
69
 
64
70
  ```ruby
65
- UniqueNamesGenerator.generate([:colors, :animals], style: :capital, separator: ' ')
71
+ generator = UniqueNamesGenerator::Generator.new([:colors, :animals], style: :capital, separator: ' ')
72
+ generator.generate
66
73
  # => Generates ex: "Lavender Marlin"
67
74
 
68
- UniqueNamesGenerator.generate([:colors, :adjectives, :animals], creativity: 8, style: :capital, separator: ' ')
75
+ generator = UniqueNamesGenerator::Generator.new([:colors, :adjectives, :animals], creativity: 8, style: :capital, separator: ' ')
76
+ generator.generate
69
77
  # => Generates ex: "Yellow Local Hippopotamus"
70
78
  ```
71
79
 
@@ -73,20 +81,22 @@ UniqueNamesGenerator.generate([:colors, :adjectives, :animals], creativity: 8, s
73
81
  Using the creativity option changes how `UniqueNamesGenerator` selects terms from the dictionaries in use, essentially acting as a multiplier. For dictionaries with a similar term length, while using a seed, the selection may at times appear to be alphabetical or closely related (ex: "Amber Anakin Skywalker"). Utilizing the `creative` option with a value between 1 and 10 will use a sequential multiplier for subsequent dictionaries providing a seemingly more "random" or "creative" result whilst still allowing for seeded generation.
74
82
 
75
83
  ```ruby
76
- UniqueNamesGenerator.generate([:colors, :adjectives, :animals], creativity: 8, seed: 'f6da7a28-5ae6-4d6b-b3b8-a197b99ed4eb')
84
+ generator = UniqueNamesGenerator::Generator.new([:colors, :adjectives, :animals], creativity: 8)
85
+ generator.generate(seed: 'f6da7a28-5ae6-4d6b-b3b8-a197b99ed4eb')
77
86
 
78
87
  # => Seed "f6da7a28-5ae6-4d6b-b3b8-a197b99ed4eb" with creativity of 8 always generates: "plum_flying_cobra"
79
88
  ```
80
89
 
81
90
  ### Seeded Generation
82
91
 
83
- A seed can be used to deterministically generate a name. As long as the provided seed and creativity values are the same between runs, then the generated name will also always be the same. Simply provide a string or integer as the value of the seed key, ie; `seed: 'hello'`.
92
+ A seed can be used to deterministically generate a name. As long as the provided seed and creativity values are the same between runs, then the generated name will also always be the same. Simply provide a string or integer as an argument to the generate method, ie; `seed: 'hello'`.
84
93
 
85
- _(**Usecase example:** generate a username for an authenticated user based on UUID. Ex: `13a5d03e-61d0-4b5b-ae3b-57953c268c5f` will always generate the name "beige_boba_fett_145" when used together with the colors/star_wars/numbers dictionaries)._
94
+ _(**Usecase example:** generate a username for an authenticated user based on UUID. Ex: `13a5d03e-61d0-4b5b-ae3b-57953c268c5f` will always generate the name "coral_greedo_320" when used together with the colors/star_wars/numbers dictionaries)._
86
95
 
87
96
  ```ruby
88
- UniqueNamesGenerator.generate([:colors, :star_wars, :numbers], seed: '13a5d03e-61d0-4b5b-ae3b-57953c268c5f')
89
- # => Seed "13a5d03e-61d0-4b5b-ae3b-57953c268c5f" always generates: "beige_boba_fett_145"
97
+ generator = UniqueNamesGenerator::Generator.new([:colors, :star_wars, :numbers])
98
+ generator.generate(seed: '13a5d03e-61d0-4b5b-ae3b-57953c268c5f')
99
+ # => Seed "13a5d03e-61d0-4b5b-ae3b-57953c268c5f" always generates: "coral_greedo_320"
90
100
  ```
91
101
 
92
102
  ## License
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module UniqueNamesGenerator
4
- VERSION = '0.1.2'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # An implementation of a unique_names_generator in Ruby
4
- # with support for PRNG/seeds
4
+ # with support for PRNG/deterministic seeds
5
5
 
6
6
  require_relative './unique_names_generator/seed'
7
7
 
@@ -15,24 +15,33 @@ require_relative './unique_names_generator/dictionaries/star_wars'
15
15
 
16
16
  # UniqueNamesGenerator implementation
17
17
  module UniqueNamesGenerator
18
- module_function
19
-
20
- def generate(dictionaries, separator: '_', style: :lowercase, seed: nil, creativity: 0)
21
- @separator = separator
22
- @style = style
23
- @seed = seed
24
- @creativity = creativity
25
-
26
- if creativity.negative? || creativity > 10
27
- raise ArgumentError, 'Outside creativity range. Must be between 0 and 10.'
18
+ # UniqueNamesGenerator::Generator
19
+ #
20
+ # This class generates unique names based on specified dictionaries and configuration options.
21
+ # It allows for customizable name generation with various styles, separators, and creativity levels.
22
+ class Generator
23
+ def initialize(dictionaries, separator: '_', style: :lowercase, creativity: 0)
24
+ @dictionaries = dictionaries
25
+ @separator = separator
26
+ @style = style
27
+ @creativity = creativity
28
+
29
+ # Will raise error if any specified dictionary is invalid
30
+ dictionaries.map { |dictionary| word_list(dictionary) }
31
+ raise ArgumentError, 'Outside creativity range. Must be between 0 and 10.' if outside_creativity_bounds?
28
32
  end
29
33
 
30
- generate_name(dictionaries)
31
- end
34
+ def generate(seed: nil)
35
+ @seed = seed
36
+ generate_name(@dictionaries)
37
+ end
32
38
 
33
- class << self
34
39
  private
35
40
 
41
+ def outside_creativity_bounds?
42
+ @creativity.negative? || @creativity > 10
43
+ end
44
+
36
45
  def match_word_list(dictionary)
37
46
  module_name = camelize_dictionary(dictionary)
38
47
  begin
@@ -146,7 +155,7 @@ module UniqueNamesGenerator
146
155
  end
147
156
 
148
157
  def raise_invalid_dictionary(dictionary)
149
- raise ArgumentError, "Invalid dictionary: #{dictionary}"
158
+ raise ArgumentError, "Invalid dictionary #{dictionary}"
150
159
  end
151
160
 
152
161
  def format_with_separator(word)
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
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
18
  'source_code_uri' => 'https://github.com/jongirard/unique_names_generator_ruby',
19
- 'documentation_uri' => 'https://jongirard.github.io/unique_names_generator_ruby' }
19
+ 'documentation_uri' => 'https://www.rubydoc.info/gems/unique_names_generator/' }
20
20
  s.require_paths = ['lib']
21
21
  s.license = 'MIT'
22
22
  s.files = Dir.chdir(File.expand_path(__dir__)) do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unique_names_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Girard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-05 00:00:00.000000000 Z
11
+ date: 2024-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -60,7 +60,7 @@ licenses:
60
60
  metadata:
61
61
  homepage_uri: https://github.com/jongirard/unique_names_generator_ruby
62
62
  source_code_uri: https://github.com/jongirard/unique_names_generator_ruby
63
- documentation_uri: https://jongirard.github.io/unique_names_generator_ruby
63
+ documentation_uri: https://www.rubydoc.info/gems/unique_names_generator/
64
64
  post_install_message:
65
65
  rdoc_options: []
66
66
  require_paths: