strgen 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +35 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +29 -0
- data/LICENSE +22 -0
- data/LICENSE.txt +21 -0
- data/README.md +58 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/strgen/version.rb +3 -0
- data/lib/strgen.rb +89 -0
- data/strgen.gemspec +26 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 628517c35933dd11f6b3c2a5cc95175081325646
|
4
|
+
data.tar.gz: cbc74078bc5a383cc84a9355bc1f4b45ace88122
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a5ed984381f9194d634e76e533a1e62213b92aee0cd2ce73e4b58a86557106f9924a1385946f1296889139ba0045bbefe7e489e20ce920502c948a6b11926195
|
7
|
+
data.tar.gz: 4efc6d58905cf78c98e37190a98bb6a9ce2a239c8f688102258b35f013b2b18fdd935de41450b2c001dd44bb66392dc361e5617eaed43eac1ac79478d18fb0b5
|
data/.gitignore
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/vendor/bundle
|
26
|
+
/lib/bundler/man/
|
27
|
+
|
28
|
+
# for a library or gem, you might want to ignore these files since the code is
|
29
|
+
# intended to run in multiple environments; otherwise, check them in:
|
30
|
+
# Gemfile.lock
|
31
|
+
# .ruby-version
|
32
|
+
# .ruby-gemset
|
33
|
+
|
34
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
35
|
+
.rvmrc
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
strgen (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
coderay (1.1.0)
|
10
|
+
method_source (0.8.2)
|
11
|
+
pry (0.10.1)
|
12
|
+
coderay (~> 1.1.0)
|
13
|
+
method_source (~> 0.8.1)
|
14
|
+
slop (~> 3.4)
|
15
|
+
rake (10.4.2)
|
16
|
+
rspec-core (3.3.2)
|
17
|
+
rspec-support (~> 3.3.0)
|
18
|
+
rspec-support (3.3.0)
|
19
|
+
slop (3.6.0)
|
20
|
+
|
21
|
+
PLATFORMS
|
22
|
+
ruby
|
23
|
+
|
24
|
+
DEPENDENCIES
|
25
|
+
bundler (~> 1.9)
|
26
|
+
pry
|
27
|
+
rake (~> 10.0)
|
28
|
+
rspec-core
|
29
|
+
strgen!
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Connor Atherton
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Connor Atherton
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# Strgen
|
2
|
+
|
3
|
+
A Ruby arbitrary string generator
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
# Default string 12 chars long
|
9
|
+
Strgen.generate
|
10
|
+
|
11
|
+
# Customised string
|
12
|
+
Strgen.generate do |c|
|
13
|
+
c.length = 30
|
14
|
+
c.symbols = false
|
15
|
+
c.repeat = false
|
16
|
+
end
|
17
|
+
```
|
18
|
+
|
19
|
+
##### Options
|
20
|
+
|
21
|
+
Include these in the config block when generating the string (see above)
|
22
|
+
|
23
|
+
**numbers** - Numbers 0-9
|
24
|
+
**symbols**
|
25
|
+
**lowercase** - The lowercase alphabet
|
26
|
+
**uppercase** - The uppercase alphabet
|
27
|
+
**alpha** - A combination of lowercase and uppercase letters.
|
28
|
+
**alphanum** - A combination of the alpha set and numbers
|
29
|
+
**length** - The length of the result string
|
30
|
+
**repeat** - Whether repeated characters are allowed
|
31
|
+
**exclude** - a character array containing individual letters to exclude
|
32
|
+
|
33
|
+
#### Example
|
34
|
+
|
35
|
+
Give me a 25 letter string containing the set of all uppercase
|
36
|
+
letters excluding the letters `A` and `B`.
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
Strgen.generate do |c|
|
40
|
+
c.lowercase = false;
|
41
|
+
c.numbers = false;
|
42
|
+
c.symbols = false;
|
43
|
+
c.length = 25;
|
44
|
+
c.exclude = %w(A B)
|
45
|
+
end
|
46
|
+
|
47
|
+
=> "WUVWREFYEOCCKOHPQCJDJTEZC"
|
48
|
+
=> "ZKCTKPLXNMFWIZWHCRVUHLHNZ"
|
49
|
+
=> "FQQDNQKZLVRJIQNFIJHKZKWSO"
|
50
|
+
```
|
51
|
+
|
52
|
+
## Contributing
|
53
|
+
|
54
|
+
1. Fork it ( https://github.com/[my-github-username]/strgen/fork )
|
55
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
56
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
57
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
58
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "strgen"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/strgen.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'strgen/version'
|
2
|
+
require 'pry'
|
3
|
+
|
4
|
+
#
|
5
|
+
# Usage:
|
6
|
+
#
|
7
|
+
# Strgen.generate do |config|
|
8
|
+
# config.length = 10
|
9
|
+
# exclude = %w(!)
|
10
|
+
# end
|
11
|
+
#
|
12
|
+
class Strgen
|
13
|
+
NUMBERS = (1..9).to_a.map(&:to_s)
|
14
|
+
LOWERCASE = ('a'..'z').to_a
|
15
|
+
UPPERCASE = ('A'..'Z').to_a
|
16
|
+
ALPHA = LOWERCASE.concat UPPERCASE
|
17
|
+
ALPHANUM = ALPHA.concat NUMBERS
|
18
|
+
SYMBOLS = %w(! @ # $ % ^ & \( \) { } [ ] - _ < > ?)
|
19
|
+
TYPES = %i(numbers lowercase uppercase symbols)
|
20
|
+
|
21
|
+
attr_accessor *TYPES, :length, :alpha, :alphanum, :exclude, :repeat
|
22
|
+
|
23
|
+
def self.generate(&block)
|
24
|
+
proxy = new
|
25
|
+
block.call(proxy) if block_given?
|
26
|
+
proxy.merge_defaults!
|
27
|
+
|
28
|
+
previous = nil
|
29
|
+
current = nil
|
30
|
+
acc = ''
|
31
|
+
characters = proxy.character_set
|
32
|
+
|
33
|
+
# store the last char in case we want to
|
34
|
+
# avoid repeating characters
|
35
|
+
proxy.length.times do
|
36
|
+
loop do
|
37
|
+
current = characters.sample
|
38
|
+
|
39
|
+
break if !proxy.exclude?(current) && (!proxy.repeat || current != previous)
|
40
|
+
end
|
41
|
+
|
42
|
+
acc += current
|
43
|
+
end
|
44
|
+
|
45
|
+
acc
|
46
|
+
end
|
47
|
+
|
48
|
+
def merge_defaults!
|
49
|
+
TYPES.each_with_object({}) do |type, acc|
|
50
|
+
acc[type] = true
|
51
|
+
acc
|
52
|
+
end.tap do |hash|
|
53
|
+
hash[:length] = 12
|
54
|
+
hash[:repeat] = true
|
55
|
+
end.each do |method, default|
|
56
|
+
next unless send(method.to_sym).nil?
|
57
|
+
send("#{method}=".to_sym, default)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def character_set
|
62
|
+
# TODO: can we do this better?
|
63
|
+
a = []
|
64
|
+
a.concat(SYMBOLS) if symbols
|
65
|
+
a.concat(ALPHANUM) if alphanum
|
66
|
+
a.concat(ALPHA) if alpha? || alpha
|
67
|
+
a.concat(NUMBERS) if alpha? || numbers
|
68
|
+
a.concat(LOWERCASE) if letters? || lowercase
|
69
|
+
a.concat(UPPERCASE) if letters? || uppercase
|
70
|
+
a
|
71
|
+
end
|
72
|
+
|
73
|
+
def exclude?(val)
|
74
|
+
return false if exclude.nil?
|
75
|
+
exclude.include? val
|
76
|
+
end
|
77
|
+
|
78
|
+
def alpha?
|
79
|
+
nil if alphanum
|
80
|
+
end
|
81
|
+
|
82
|
+
def letters?
|
83
|
+
nil if alpha
|
84
|
+
end
|
85
|
+
|
86
|
+
def pick_all?
|
87
|
+
!lowercase && !uppercase && !alpha && !alphanum && !symbols
|
88
|
+
end
|
89
|
+
end
|
data/strgen.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'strgen/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "strgen"
|
8
|
+
spec.version = Strgen::VERSION
|
9
|
+
spec.authors = ["Connor Atherton"]
|
10
|
+
spec.email = ["c.liam.atherton@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Ruby arbitrary string generator}
|
13
|
+
spec.description = %q{Ruby arbitrary string generator}
|
14
|
+
spec.homepage = "https://github.com/ConnorAtherton/strgen"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec-core"
|
25
|
+
spec.add_development_dependency "pry"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: strgen
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Connor Atherton
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-20 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.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
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'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec-core
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Ruby arbitrary string generator
|
70
|
+
email:
|
71
|
+
- c.liam.atherton@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- CODE_OF_CONDUCT.md
|
80
|
+
- Gemfile
|
81
|
+
- Gemfile.lock
|
82
|
+
- LICENSE
|
83
|
+
- LICENSE.txt
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- bin/console
|
87
|
+
- bin/setup
|
88
|
+
- lib/strgen.rb
|
89
|
+
- lib/strgen/version.rb
|
90
|
+
- strgen.gemspec
|
91
|
+
homepage: https://github.com/ConnorAtherton/strgen
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.2.2
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Ruby arbitrary string generator
|
115
|
+
test_files: []
|