classnamer 3.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +19 -0
- data/README.rdoc +57 -0
- data/bin/classnamer +20 -0
- data/classnamer.gemspec +20 -0
- data/lib/classnamer.rb +70 -0
- data/test/classnamer_test.rb +73 -0
- metadata +53 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 739adbbcad3a5bcf1cca2cdd2382c2353f2ab8c42a0f1e8d26aff6dccb9cbe8b
|
4
|
+
data.tar.gz: fca286e359dd7d1e24a8475bd24f4e93c77528ddddcc01c905376e4b819c6d97
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5dc4755ce5009c9e96b2c3e3f46d71c52a32cf9c2ff1d1686d786507cb3424f3085a7d68d43a9dcb62c9ef33313a5756acaeba80a2a22480715ad09bf9078fa1
|
7
|
+
data.tar.gz: 6bd9610baaec2587275b4514185452d203266834e1bdcbb2b49ee343e87e466e01511bd98a68792249d34f0e9050c7d71b90db3848e1c90d9f11bd8a48db82e3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2018 Aaron Beckerman
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
7
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
8
|
+
so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
= \Classnamer
|
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.
|
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
|
+
|
10
|
+
|
11
|
+
== Using the command-line program
|
12
|
+
|
13
|
+
$ classnamer
|
14
|
+
PrioritizedUploadWrapper
|
15
|
+
|
16
|
+
|
17
|
+
== Using in Ruby code
|
18
|
+
|
19
|
+
You can generate a random class name like this:
|
20
|
+
|
21
|
+
require 'classnamer'
|
22
|
+
puts Classnamer.generate # => PrioritizedUploadWrapper
|
23
|
+
|
24
|
+
You can customize how class names are generated. Classnamer will generate
|
25
|
+
random class names by concatenating randomly-selected elements of arrays that
|
26
|
+
you provide.
|
27
|
+
|
28
|
+
puts Classnamer.generate([%w{Foo Bar}, %w{Baz Qux}]) # => FooQux
|
29
|
+
|
30
|
+
You can also specify a custom random number generator. Maybe you don't even
|
31
|
+
want it to be random.
|
32
|
+
|
33
|
+
puts Classnamer.generate([%w{Foo Bar}, %w{Baz Qux}], lambda { |_| 0 })
|
34
|
+
# => FooBaz
|
35
|
+
|
36
|
+
If you plan to use the same customizations multiple times, you can create
|
37
|
+
a Classnamer::Generator object for that.
|
38
|
+
|
39
|
+
generator = Classnamer::Generator.new([%w{Foo Bar}, %w{Baz Qux}])
|
40
|
+
generator.generate # => FooQux
|
41
|
+
generator.generate # => BarQux
|
42
|
+
|
43
|
+
|
44
|
+
== Author
|
45
|
+
|
46
|
+
This was written by Aaron Beckerman.
|
47
|
+
|
48
|
+
|
49
|
+
== Acknowledgements
|
50
|
+
|
51
|
+
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
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'classnamer'
|
5
|
+
|
6
|
+
OptionParser.new do |opts|
|
7
|
+
opts.banner = 'Usage: classnamer [options]'
|
8
|
+
|
9
|
+
opts.on_tail '-v', '--version', 'Show version number' do
|
10
|
+
puts Classnamer::VERSION
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
|
14
|
+
opts.on_tail '-h', '--help', 'Show this message' do
|
15
|
+
puts opts
|
16
|
+
exit
|
17
|
+
end
|
18
|
+
end.parse!
|
19
|
+
|
20
|
+
puts Classnamer.generate
|
data/classnamer.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "classnamer"
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "classnamer"
|
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
|
14
|
+
s.required_ruby_version = ">= 1.8.7"
|
15
|
+
s.bindir = "bin"
|
16
|
+
s.files = ["LICENSE.txt", "README.rdoc", "bin/classnamer", "classnamer.gemspec", "lib/classnamer.rb", "test/classnamer_test.rb"]
|
17
|
+
s.test_files = ["test/classnamer_test.rb"]
|
18
|
+
s.executables = ["classnamer"]
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
end
|
data/lib/classnamer.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# This module randomly generates class names, such as
|
2
|
+
# "PrioritizedUploadWrapper". It does this by concatenating several parts
|
3
|
+
# ("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
|
6
|
+
# is called a part candidate matrix.
|
7
|
+
module Classnamer
|
8
|
+
|
9
|
+
# The library's version string.
|
10
|
+
VERSION = '3.0.8'
|
11
|
+
|
12
|
+
# The default part candidate matrix, used by generate.
|
13
|
+
PART_CANDIDATE_MATRIX = [
|
14
|
+
%w{Threadsafe Optimized Stable Automatic Abstract Serializable Writable
|
15
|
+
Readable Blocking Nonblocking Scriptable Smart Basic Remote Simple
|
16
|
+
Secure Cryptographic Flexible Configurable Internal Cloneable Legacy
|
17
|
+
Recursive Multiple Threaded Virtual Singleton Stateless Stateful
|
18
|
+
Localized Prioritized Generic Dynamic Shared Modal Fast Temporary},
|
19
|
+
%w{Byte Task Object Resource Mutex Memory List Node File Lock Pixel
|
20
|
+
Character Command Client Server Socket Thread Notification Keystroke
|
21
|
+
Timestamp Raster String Hash Integer Cache Scrollbar Grid Package
|
22
|
+
Connection Database Graph Row Column Record Metadata Transaction Message
|
23
|
+
Request Response Query Statement Result Upload Download User Directory
|
24
|
+
Button Device Search Lolcat Robot},
|
25
|
+
%w{Sorter Allocator Tokenizer Writer Reader Randomizer Initializer Factory
|
26
|
+
Panel Frame Container Compressor Expander Counter Collector Collection
|
27
|
+
Wrapper Accumulator Table Marshaller Demarshaller Extractor Parser
|
28
|
+
Scanner Interpreter Validator Window Dialog Stream Listener Event
|
29
|
+
Exception Vector Lexer Analyzer Iterator Set Tree Concatenator Monitor
|
30
|
+
Tester Buffer Selector Visitor Adapter Helper Annotation Permission
|
31
|
+
Info Action Channel Filter Manager Mediator Operation Context Queue
|
32
|
+
Stack View Engine Publisher Subscriber Delegator State Processor Handler
|
33
|
+
Generator Dispatcher Bundle Builder Logger Iterator Observer Encoder
|
34
|
+
Decoder Importer Exporter Util Policy Preference Formatter Sequence
|
35
|
+
Comparator Definition Timer Classifier Controller Loader Converter
|
36
|
+
Constraint Module Migrator Descriptor Process}
|
37
|
+
]
|
38
|
+
|
39
|
+
# 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+ must have a "call" method that takes one integer
|
48
|
+
# argument (an array length) and acts like Kernel::rand.
|
49
|
+
def self.generate(matrix = self::PART_CANDIDATE_MATRIX, prng = self::PRNG)
|
50
|
+
matrix.map { |a| a[prng.call a.length] }.join ''
|
51
|
+
end
|
52
|
+
|
53
|
+
# A class name generator that always uses the specified part candidate matrix
|
54
|
+
# and index generator.
|
55
|
+
class Generator
|
56
|
+
# Creates a class name generator with the specified part candidate matrix
|
57
|
+
# and index generator.
|
58
|
+
def initialize(matrix = Classnamer::PART_CANDIDATE_MATRIX,
|
59
|
+
prng = Classnamer::PRNG)
|
60
|
+
@matrix = matrix
|
61
|
+
@prng = prng
|
62
|
+
end
|
63
|
+
|
64
|
+
# Generates a class name using the part candidate matrix and index
|
65
|
+
# generator passed in when the object was created.
|
66
|
+
def generate
|
67
|
+
Classnamer.generate @matrix, @prng
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'classnamer'
|
2
|
+
|
3
|
+
String == Classnamer::VERSION.class or fail
|
4
|
+
|
5
|
+
3 == Classnamer::PART_CANDIDATE_MATRIX.length or fail
|
6
|
+
|
7
|
+
Classnamer::PART_CANDIDATE_MATRIX.flatten(1).
|
8
|
+
all? { |part_candidate| /\A[A-Z]/ =~ part_candidate } or fail
|
9
|
+
|
10
|
+
Classnamer.respond_to?(:generate) or fail
|
11
|
+
|
12
|
+
String == Classnamer.generate.class or fail
|
13
|
+
|
14
|
+
'42ObjecttrueSymbolFoo' == Classnamer.generate(
|
15
|
+
[[42], [Object], [nil], [true], [:Symbol], ['Foo']]) or fail
|
16
|
+
|
17
|
+
lambda do
|
18
|
+
matrix = [%w{A B C}, [], %w{A B}, %w{A}]
|
19
|
+
prng_args = []
|
20
|
+
prng = lambda { |n|
|
21
|
+
prng_args << n
|
22
|
+
0
|
23
|
+
}
|
24
|
+
Classnamer.generate matrix, prng
|
25
|
+
[3, 0, 2, 1] == prng_args or fail
|
26
|
+
end.call
|
27
|
+
|
28
|
+
lambda do
|
29
|
+
matrix = [%w{Foo0 Foo1 Foo2}, %w{Bar0 Bar1 Bar2}, %w{Baz0 Baz1 Baz2}]
|
30
|
+
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
|
38
|
+
|
39
|
+
'' == Classnamer.generate([[], [], []]) or fail
|
40
|
+
|
41
|
+
begin
|
42
|
+
Classnamer.generate nil
|
43
|
+
rescue NoMethodError
|
44
|
+
else
|
45
|
+
fail
|
46
|
+
end
|
47
|
+
|
48
|
+
begin
|
49
|
+
Classnamer.generate Classnamer::PART_CANDIDATE_MATRIX, nil
|
50
|
+
rescue NoMethodError
|
51
|
+
else
|
52
|
+
fail
|
53
|
+
end
|
54
|
+
|
55
|
+
begin
|
56
|
+
Classnamer.generate [['Foo'], nil]
|
57
|
+
rescue NoMethodError
|
58
|
+
else
|
59
|
+
fail
|
60
|
+
end
|
61
|
+
|
62
|
+
Classnamer::Generator == Classnamer::Generator.new.class or fail
|
63
|
+
|
64
|
+
Classnamer::Generator.new.respond_to?(:generate) or fail
|
65
|
+
|
66
|
+
lambda do
|
67
|
+
matrix = [%w{Foo0 Foo1 Foo2}, %w{Bar0 Bar1 Bar2}, %w{Baz0 Baz1 Baz2}]
|
68
|
+
indices = [0, 2, 1]
|
69
|
+
generator = Classnamer::Generator.new(matrix, lambda { |_| indices.shift })
|
70
|
+
'Foo0Bar2Baz1' == generator.generate or fail
|
71
|
+
end.call
|
72
|
+
|
73
|
+
puts 'Test finished.'
|
metadata
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: classnamer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 3.0.8
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aaron Beckerman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-28 00:00:00.000000000 Z
|
12
|
+
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:
|
18
|
+
- classnamer
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- LICENSE.txt
|
23
|
+
- README.rdoc
|
24
|
+
- bin/classnamer
|
25
|
+
- classnamer.gemspec
|
26
|
+
- lib/classnamer.rb
|
27
|
+
- test/classnamer_test.rb
|
28
|
+
homepage:
|
29
|
+
licenses:
|
30
|
+
- MIT
|
31
|
+
metadata: {}
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.8.7
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
requirements: []
|
47
|
+
rubyforge_project:
|
48
|
+
rubygems_version: 2.7.6
|
49
|
+
signing_key:
|
50
|
+
specification_version: 4
|
51
|
+
summary: A random class name generator.
|
52
|
+
test_files:
|
53
|
+
- test/classnamer_test.rb
|