classnamer 3.0.9 → 3.0.11

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2022 Aaron Beckerman
1
+ Copyright (c) 2024 Aaron Beckerman
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of
4
4
  this software and associated documentation files (the "Software"), to deal in
@@ -1,24 +1,21 @@
1
- = \Classnamer
1
+ Classnamer
2
2
 
3
- Classnamer randomly generates tongue-in-cheek class names suitable for
4
- enterprise-friendly object-oriented programming languages like C++ and Java. It
5
- includes a library and a command-line program.
3
+ Classnamer randomly generates facetious class names suitable for
4
+ object-oriented programming languages like C++ and Java. It includes a Ruby
5
+ library and command-line program.
6
6
 
7
- This code is packaged as a RubyGem and tested on the following branches of
8
- MRI (Matz's Ruby Interpreter): 1.8.7, 1.9.3, 2.0.0, 2.1.x, and 2.2.x.
9
7
 
10
-
11
- == Using the command-line program
8
+ Using the command-line program
12
9
 
13
10
  $ classnamer
14
11
  PrioritizedUploadWrapper
15
12
 
16
13
 
17
- == Using in Ruby code
14
+ Using in Ruby code
18
15
 
19
16
  You can generate a random class name like this:
20
17
 
21
- require 'classnamer'
18
+ require "classnamer"
22
19
  puts Classnamer.generate # => PrioritizedUploadWrapper
23
20
 
24
21
  You can customize how class names are generated. Classnamer will generate
@@ -41,17 +38,6 @@ a Classnamer::Generator object for that.
41
38
  generator.generate # => BarQux
42
39
 
43
40
 
44
- == Author
45
-
46
- This was written by Aaron Beckerman.
47
-
48
-
49
- == Acknowledgements
41
+ Acknowledgements
50
42
 
51
43
  Thanks to Luiz Signorelli and Marta Paciorkowska for their suggestions.
52
-
53
-
54
- == Copyright
55
-
56
- This code is distributed under the MIT License (also known as the Expat
57
- License). See the LICENSE.txt file for details.
data/bin/classnamer CHANGED
@@ -1,17 +1,17 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'optparse'
4
- require 'classnamer'
3
+ require "optparse"
4
+ require "classnamer"
5
5
 
6
6
  OptionParser.new do |opts|
7
- opts.banner = 'Usage: classnamer [options]'
7
+ opts.banner = "Usage: classnamer [options]"
8
8
 
9
- opts.on_tail '-v', '--version', 'Show version number' do
9
+ opts.on_tail "-v", "--version", "Show version number" do
10
10
  puts Classnamer::VERSION
11
11
  exit
12
12
  end
13
13
 
14
- opts.on_tail '-h', '--help', 'Show this message' do
14
+ opts.on_tail "-h", "--help", "Show this message" do
15
15
  puts opts
16
16
  exit
17
17
  end
data/classnamer.gemspec CHANGED
@@ -6,15 +6,13 @@ require "classnamer"
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "classnamer"
8
8
  s.version = Classnamer::VERSION
9
- s.author = "Aaron Beckerman"
10
- s.summary = %q{A random class name generator.}
11
- s.description = %q{Classnamer randomly generates tongue-in-cheek class names suitable for enterprise-friendly object-oriented programming languages like C++ and Java. It includes a library and a command-line program.}
12
- s.license = "MIT"
13
- s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Aaron Beckerman"]
10
+ s.summary = "A random class name generator."
11
+ s.description = "Classnamer randomly generates facetious class names suitable for object-oriented programming languages like C++ and Java. It includes a library and command-line program."
12
+ s.licenses = ["MIT"]
14
13
  s.required_ruby_version = ">= 1.8.7"
15
14
  s.bindir = "bin"
16
- s.files = ["LICENSE.txt", "README.rdoc", "bin/classnamer", "classnamer.gemspec", "lib/classnamer.rb", "test/classnamer_test.rb"]
15
+ s.files = ["LICENSE.txt", "README.txt", "bin/classnamer", "classnamer.gemspec", "lib/classnamer.rb", "test/classnamer_test.rb"]
17
16
  s.test_files = ["test/classnamer_test.rb"]
18
17
  s.executables = ["classnamer"]
19
- s.require_paths = ["lib"]
20
18
  end
data/lib/classnamer.rb CHANGED
@@ -1,15 +1,21 @@
1
+ ##
1
2
  # This module randomly generates class names, such as
2
3
  # "PrioritizedUploadWrapper". It does this by concatenating several parts
3
4
  # ("Prioritized", "Upload", and "Wrapper", in this case), which are strings
4
- # randomly selected from arrays of candidates. ("Prioritized", "Upload", and
5
- # "Wrapper" were each selected from a different array.) An array of such arrays
5
+ # randomly selected from arrays of candidates ("Prioritized", "Upload", and
6
+ # "Wrapper" were each selected from a different array). An array of such arrays
6
7
  # is called a part candidate matrix.
8
+
7
9
  module Classnamer
8
10
 
11
+ ##
9
12
  # The library's version string.
10
- VERSION = '3.0.9'
11
13
 
14
+ VERSION = "3.0.11"
15
+
16
+ ##
12
17
  # The default part candidate matrix, used by generate.
18
+
13
19
  PART_CANDIDATE_MATRIX = [
14
20
  %w{Threadsafe Optimized Stable Automatic Abstract Serializable Writable
15
21
  Readable Blocking Nonblocking Scriptable Smart Basic Remote Simple
@@ -36,36 +42,48 @@ module Classnamer
36
42
  Constraint Module Migrator Descriptor Process}
37
43
  ]
38
44
 
45
+ ##
39
46
  # The default index generator, used by generate.
40
- PRNG = ::Kernel.method(:rand)
41
-
42
- # This method does the actual work of randomly generating a class name. It
43
- # takes two arguments, both optional: a part candidate matrix (+matrix+) and
44
- # an index generator (+prng+). If +matrix+ is not specified, the module's
45
- # default part candidate matrix (PART_CANDIDATE_MATRIX) is used. If +prng+ is
46
- # not specified, Kernel::rand is used. +matrix+ must act like an array of
47
- # arrays of strings. +prng+ will be sent "call" messages with one integer
48
- # argument (an array length) and must act like Kernel::rand with an integer
49
- # argument.
50
- def self.generate(matrix = self::PART_CANDIDATE_MATRIX, prng = self::PRNG)
51
- matrix.map { |a| a[prng.call a.length] }.join ''
47
+
48
+ PRNG = ::Kernel.method :rand
49
+
50
+ ##
51
+ # Randomly generates a class name and returns it. This method takes two
52
+ # arguments, both optional: a part candidate matrix (+matrix+) and an index
53
+ # generator (+prng+). If +matrix+ is not specified, the module's default part
54
+ # candidate matrix (PART_CANDIDATE_MATRIX) is used. If +prng+ is not
55
+ # specified, Kernel::rand is used. +matrix+ must act like an array of arrays
56
+ # of strings. +prng+ will be sent call messages with one integer argument
57
+ # (an array length) and must act like Kernel::rand with an integer argument.
58
+
59
+ def self.generate matrix = PART_CANDIDATE_MATRIX, prng = PRNG
60
+ matrix.map { |a| a[prng.call a.length] }.join ""
52
61
  end
53
62
 
63
+ ##
54
64
  # A class name generator that always uses the specified part candidate matrix
55
65
  # and index generator.
66
+
56
67
  class Generator
68
+
69
+ ##
57
70
  # Creates a class name generator with the specified part candidate matrix
58
71
  # and index generator.
59
- def initialize(matrix = Classnamer::PART_CANDIDATE_MATRIX,
60
- prng = Classnamer::PRNG)
72
+
73
+ def initialize matrix = PART_CANDIDATE_MATRIX, prng = PRNG
61
74
  @matrix = matrix
62
75
  @prng = prng
76
+ nil
63
77
  end
64
78
 
65
- # Generates a class name using the part candidate matrix and index
66
- # generator passed in when the object was created.
79
+ ##
80
+ # Generates and returns a class name using the part candidate matrix and
81
+ # index generator specified when the generator was created.
82
+
67
83
  def generate
68
84
  Classnamer.generate @matrix, @prng
69
85
  end
86
+
70
87
  end
88
+
71
89
  end
@@ -1,20 +1,48 @@
1
- require 'classnamer'
1
+ # Sections that create local variables are in class definitions so that later
2
+ # sections cannot accidentally reference those local variables.
2
3
 
3
- String == Classnamer::VERSION.class or fail
4
+ require "classnamer"
4
5
 
5
- 3 == Classnamer::PART_CANDIDATE_MATRIX.length or fail
6
+ # Classnamer should be a module.
7
+ fail "" unless Module.equal? Classnamer.class
6
8
 
7
- Classnamer::PART_CANDIDATE_MATRIX.flatten(1).
8
- all? { |part_candidate| /\A[A-Z]/ =~ part_candidate } or fail
9
+ # The version constant should be a string.
10
+ fail "" unless String.equal? Classnamer::VERSION.class
9
11
 
10
- Classnamer.respond_to?(:generate) or fail
12
+ # The default part candidate matrix should be an array.
13
+ fail "" unless Array.equal? Classnamer::PART_CANDIDATE_MATRIX.class
11
14
 
12
- String == Classnamer.generate.class or fail
15
+ # The default part candidate matrix should have three sections.
16
+ fail "" unless 3 == Classnamer::PART_CANDIDATE_MATRIX.length
13
17
 
14
- '42ObjecttrueSymbolFoo' == Classnamer.generate(
15
- [[42], [Object], [nil], [true], [:Symbol], ['Foo']]) or fail
18
+ # The default part candidate matrix should contain only arrays.
19
+ fail "" unless Classnamer::PART_CANDIDATE_MATRIX.
20
+ all? { |elem| ::Array.equal? elem.class }
16
21
 
17
- lambda do
22
+ # Each default part candidate should start with an uppercase English letter.
23
+ fail "" unless Classnamer::PART_CANDIDATE_MATRIX.flatten(1).
24
+ all? { |part_candidate| /\A[A-Z]/ =~ part_candidate }
25
+
26
+ # The default index generator should be a wrapper around Kernel.rand.
27
+ fail "" unless Kernel.method(:rand) == Classnamer::PRNG
28
+
29
+ # The default index generator should return a valid index when a call message
30
+ # is sent to it with a length argument.
31
+ fail "" unless 0 == Classnamer::PRNG.call(1)
32
+
33
+ # Classnamer should say it responds to generate messages.
34
+ fail "" unless Classnamer.respond_to? :generate
35
+
36
+ # Classnamer.generate should return a string.
37
+ fail "" unless String.equal? Classnamer.generate.class
38
+
39
+ # Classnamer.generate should convert all the parts to strings.
40
+ fail "" unless "42ObjecttrueSymbolFoo" ==
41
+ Classnamer.generate([[42], [Object], [nil], [true], [:Symbol], ["Foo"]])
42
+
43
+ # Classnamer.generate should send the expected messages to the index generator
44
+ # given as an argument.
45
+ class ::Object
18
46
  matrix = [%w{A B C}, [], %w{A B}, %w{A}]
19
47
  prng_args = []
20
48
  prng = lambda { |n|
@@ -22,52 +50,73 @@ lambda do
22
50
  0
23
51
  }
24
52
  Classnamer.generate matrix, prng
25
- [3, 0, 2, 1] == prng_args or fail
26
- end.call
53
+ fail "" unless [3, 0, 2, 1] == prng_args
54
+ end
27
55
 
28
- lambda do
56
+ # Classnamer should return the expected string when sent a generate message
57
+ # with a deterministic index generator as an argument.
58
+ class ::Object
29
59
  matrix = [%w{Foo0 Foo1 Foo2}, %w{Bar0 Bar1 Bar2}, %w{Baz0 Baz1 Baz2}]
30
60
  indices = [0, 2, 1]
31
- 'Foo0Bar2Baz1' == Classnamer.generate(matrix, lambda { |_| indices.shift }) \
32
- or fail
33
- end.call
34
-
35
- 'Foo' == Classnamer.generate([['Foo']]) or fail
36
-
37
- '' == Classnamer.generate([]) or fail
61
+ fail "" unless "Foo0Bar2Baz1" ==
62
+ Classnamer.generate(matrix, lambda { |_| indices.shift })
63
+ end
38
64
 
39
- '' == Classnamer.generate([[], [], []]) or fail
65
+ # Classnamer.generate should return the expected strings when given part
66
+ # candidate matrices consisting of empty and single-element arrays.
67
+ fail "" unless "Foo" == Classnamer.generate([["Foo"]])
68
+ fail "" unless "" == Classnamer.generate([])
69
+ fail "" unless "" == Classnamer.generate([[], [], []])
70
+
71
+ # Classnamer.generate should create a new string and not modify any parts.
72
+ class ::Object
73
+ a = "a"
74
+ b = "b"
75
+ name = Classnamer.generate [[a], [b]]
76
+ fail "" if a.equal? name
77
+ fail "" if b.equal? name
78
+ fail "" unless "a" == a
79
+ fail "" unless "b" == b
80
+ end
40
81
 
82
+ # Classnamer.generate should raise an exception when given a part candidate
83
+ # matrix that does not conform to the expected interface as an argument.
41
84
  begin
42
85
  Classnamer.generate nil
43
86
  rescue NoMethodError
44
87
  else
45
- fail
88
+ fail ""
46
89
  end
47
-
48
90
  begin
49
- Classnamer.generate Classnamer::PART_CANDIDATE_MATRIX, nil
91
+ Classnamer.generate [["Foo"], nil]
50
92
  rescue NoMethodError
51
93
  else
52
- fail
94
+ fail ""
53
95
  end
54
96
 
97
+ # Classnamer.generate should raise an exception when given an index generator
98
+ # that does not conform to the expected interface as an argument.
55
99
  begin
56
- Classnamer.generate [['Foo'], nil]
100
+ Classnamer.generate Classnamer::PART_CANDIDATE_MATRIX, nil
57
101
  rescue NoMethodError
58
102
  else
59
- fail
103
+ fail ""
60
104
  end
61
105
 
62
- Classnamer::Generator == Classnamer::Generator.new.class or fail
106
+ # Classnamer::Generator.new should return a generator of the expected class.
107
+ fail "" unless Classnamer::Generator.equal? Classnamer::Generator.new.class
63
108
 
64
- Classnamer::Generator.new.respond_to?(:generate) or fail
109
+ # A generator should say it responds to generate messages.
110
+ fail "" unless Classnamer::Generator.new.respond_to? :generate
65
111
 
66
- lambda do
112
+ # A generator with a deterministic index generator should return the expected
113
+ # name when sent a generate message.
114
+ class ::Object
67
115
  matrix = [%w{Foo0 Foo1 Foo2}, %w{Bar0 Bar1 Bar2}, %w{Baz0 Baz1 Baz2}]
68
116
  indices = [0, 2, 1]
69
- generator = Classnamer::Generator.new(matrix, lambda { |_| indices.shift })
70
- 'Foo0Bar2Baz1' == generator.generate or fail
71
- end.call
117
+ generator = Classnamer::Generator.new matrix, lambda { |_| indices.shift }
118
+ fail "" unless "Foo0Bar2Baz1" == generator.generate
119
+ end
72
120
 
73
- puts 'Test finished.'
121
+ # If this message doesn't get written, there was a problem.
122
+ puts "Test finished: #{__FILE__}"
metadata CHANGED
@@ -1,52 +1,74 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: classnamer
3
- version: !ruby/object:Gem::Version
4
- version: 3.0.9
3
+ version: !ruby/object:Gem::Version
4
+ hash: 17
5
+ prerelease:
6
+ segments:
7
+ - 3
8
+ - 0
9
+ - 11
10
+ version: 3.0.11
5
11
  platform: ruby
6
- authors:
12
+ authors:
7
13
  - Aaron Beckerman
8
- autorequire:
14
+ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
- date: 2022-11-13 00:00:00.000000000 Z
17
+
18
+ date: 2024-03-15 00:00:00 -07:00
19
+ default_executable:
12
20
  dependencies: []
13
- description: Classnamer randomly generates tongue-in-cheek class names suitable for
14
- enterprise-friendly object-oriented programming languages like C++ and Java. It
15
- includes a library and a command-line program.
16
- email:
17
- executables:
21
+
22
+ description: Classnamer randomly generates facetious class names suitable for object-oriented programming languages like C++ and Java. It includes a library and command-line program.
23
+ email:
24
+ executables:
18
25
  - classnamer
19
26
  extensions: []
27
+
20
28
  extra_rdoc_files: []
21
- files:
29
+
30
+ files:
22
31
  - LICENSE.txt
23
- - README.rdoc
32
+ - README.txt
24
33
  - bin/classnamer
25
34
  - classnamer.gemspec
26
35
  - lib/classnamer.rb
27
36
  - test/classnamer_test.rb
28
- homepage:
29
- licenses:
37
+ has_rdoc: true
38
+ homepage:
39
+ licenses:
30
40
  - MIT
31
- metadata: {}
32
- post_install_message:
41
+ post_install_message:
33
42
  rdoc_options: []
34
- require_paths:
43
+
44
+ require_paths:
35
45
  - lib
36
- required_ruby_version: !ruby/object:Gem::Requirement
37
- requirements:
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
38
49
  - - ">="
39
- - !ruby/object:Gem::Version
50
+ - !ruby/object:Gem::Version
51
+ hash: 57
52
+ segments:
53
+ - 1
54
+ - 8
55
+ - 7
40
56
  version: 1.8.7
41
- required_rubygems_version: !ruby/object:Gem::Requirement
42
- requirements:
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
43
60
  - - ">="
44
- - !ruby/object:Gem::Version
45
- version: '0'
61
+ - !ruby/object:Gem::Version
62
+ hash: 3
63
+ segments:
64
+ - 0
65
+ version: "0"
46
66
  requirements: []
47
- rubygems_version: 3.3.7
48
- signing_key:
49
- specification_version: 4
67
+
68
+ rubyforge_project:
69
+ rubygems_version: 1.6.2
70
+ signing_key:
71
+ specification_version: 3
50
72
  summary: A random class name generator.
51
- test_files:
73
+ test_files:
52
74
  - test/classnamer_test.rb
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA256:
3
- metadata.gz: d27a21e3575373a7dd8339fc51f8f06fa691ec94575523da070ccd4afe8608cc
4
- data.tar.gz: 1de71f5634a0f8ab76f4cdafd584489e8cbe10ea14de32f8cfb264291c512037
5
- SHA512:
6
- metadata.gz: e3b75eee842eb2de0866e81c81e9457db9622e4fbe7ab8c914fc954c23393c54371eb69a722cc23d00cd490148aca40762d743f1a15c04c157ae5cce9f046469
7
- data.tar.gz: 3e14a92ade9675a6e15210a7f14e7d17a3d09ac764d6e61fe101c0f61cf9dea733c2707f56458a1d65c3af04522d8e4b14eb7cf1e8393c7c6ae156ea68a6826e