strgen 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +0 -1
- data/Gemfile.lock +12 -1
- data/README.md +15 -15
- data/lib/strgen.rb +15 -9
- data/lib/strgen/version.rb +1 -1
- data/strgen.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79789edc5347ff826508218b4fe08e2a5fe9e07e
|
4
|
+
data.tar.gz: 695092343161e8fc6fb54e18556e286c470bbad8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4778b29071698bfb8905c92f9f6d72eff399025ae35e19bde6cb54d9f3d942c5b43cc800aab05e44670457d6ee8dd3d05b13f9a919a127ff93d4add66f19815c
|
7
|
+
data.tar.gz: e725a27b7d3a5b17cf82b5e0b9d064ca0f7d10da2ee93b1c8f265c0f9bb9ab887aa87ebf72a01105b66ef6bae64fa0868494bbd31ef0fad3041d01fe0fbd6129
|
data/.rspec
CHANGED
data/Gemfile.lock
CHANGED
@@ -7,14 +7,25 @@ GEM
|
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
coderay (1.1.0)
|
10
|
+
diff-lcs (1.2.5)
|
10
11
|
method_source (0.8.2)
|
11
12
|
pry (0.10.1)
|
12
13
|
coderay (~> 1.1.0)
|
13
14
|
method_source (~> 0.8.1)
|
14
15
|
slop (~> 3.4)
|
15
16
|
rake (10.4.2)
|
17
|
+
rspec (3.3.0)
|
18
|
+
rspec-core (~> 3.3.0)
|
19
|
+
rspec-expectations (~> 3.3.0)
|
20
|
+
rspec-mocks (~> 3.3.0)
|
16
21
|
rspec-core (3.3.2)
|
17
22
|
rspec-support (~> 3.3.0)
|
23
|
+
rspec-expectations (3.3.1)
|
24
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
25
|
+
rspec-support (~> 3.3.0)
|
26
|
+
rspec-mocks (3.3.2)
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
+
rspec-support (~> 3.3.0)
|
18
29
|
rspec-support (3.3.0)
|
19
30
|
slop (3.6.0)
|
20
31
|
|
@@ -25,5 +36,5 @@ DEPENDENCIES
|
|
25
36
|
bundler (~> 1.9)
|
26
37
|
pry
|
27
38
|
rake (~> 10.0)
|
28
|
-
rspec
|
39
|
+
rspec
|
29
40
|
strgen!
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# Strgen
|
1
|
+
# Strgen ![Build Status](https://api.travis-ci.org/ConnorAtherton/strgen.svg)
|
2
2
|
|
3
|
-
|
3
|
+
An arbitrary Ruby string generator
|
4
4
|
|
5
5
|
## Usage
|
6
6
|
|
@@ -20,15 +20,15 @@ end
|
|
20
20
|
|
21
21
|
Include these in the config block when generating the string (see above)
|
22
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
|
23
|
+
- **numbers** - Numbers 0-9
|
24
|
+
- **symbols** - The following set `[! @ # $ % ^ & ( ) { } [ ] - _ < > ?]`
|
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
32
|
|
33
33
|
#### Example
|
34
34
|
|
@@ -37,10 +37,10 @@ letters excluding the letters `A` and `B`.
|
|
37
37
|
|
38
38
|
```ruby
|
39
39
|
Strgen.generate do |c|
|
40
|
-
c.lowercase = false
|
41
|
-
c.numbers = false
|
42
|
-
c.symbols = false
|
43
|
-
c.length = 25
|
40
|
+
c.lowercase = false
|
41
|
+
c.numbers = false
|
42
|
+
c.symbols = false
|
43
|
+
c.length = 25
|
44
44
|
c.exclude = %w(A B)
|
45
45
|
end
|
46
46
|
|
data/lib/strgen.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
require 'strgen/version'
|
2
|
-
require 'pry'
|
3
2
|
|
4
3
|
#
|
5
4
|
# Usage:
|
6
5
|
#
|
7
|
-
# Strgen.generate do
|
8
|
-
#
|
6
|
+
# Strgen.generate do
|
7
|
+
# length = 10
|
9
8
|
# exclude = %w(!)
|
10
9
|
# end
|
11
10
|
#
|
@@ -13,18 +12,27 @@ class Strgen
|
|
13
12
|
NUMBERS = (1..9).to_a.map(&:to_s)
|
14
13
|
LOWERCASE = ('a'..'z').to_a
|
15
14
|
UPPERCASE = ('A'..'Z').to_a
|
16
|
-
ALPHA = LOWERCASE.concat UPPERCASE
|
17
|
-
ALPHANUM = ALPHA.concat NUMBERS
|
15
|
+
ALPHA = LOWERCASE.dup.concat UPPERCASE
|
16
|
+
ALPHANUM = ALPHA.dup.concat NUMBERS
|
18
17
|
SYMBOLS = %w(! @ # $ % ^ & \( \) { } [ ] - _ < > ?)
|
19
18
|
TYPES = %i(numbers lowercase uppercase symbols)
|
20
19
|
|
21
20
|
attr_accessor *TYPES, :length, :alpha, :alphanum, :exclude, :repeat
|
22
21
|
|
22
|
+
# Errors
|
23
|
+
class InvalidLengthError < StandardError; end
|
24
|
+
|
23
25
|
def self.generate(&block)
|
24
26
|
proxy = new
|
25
|
-
|
27
|
+
|
28
|
+
if block_given?
|
29
|
+
block.arity > 0 ? block.call(proxy) : proxy.instance_eval(&block)
|
30
|
+
end
|
31
|
+
|
26
32
|
proxy.merge_defaults!
|
27
33
|
|
34
|
+
raise InvalidLengthError if proxy.length < 1
|
35
|
+
|
28
36
|
previous = nil
|
29
37
|
current = nil
|
30
38
|
acc = ''
|
@@ -35,7 +43,6 @@ class Strgen
|
|
35
43
|
proxy.length.times do
|
36
44
|
loop do
|
37
45
|
current = characters.sample
|
38
|
-
|
39
46
|
break if !proxy.exclude?(current) && (!proxy.repeat || current != previous)
|
40
47
|
end
|
41
48
|
|
@@ -50,8 +57,7 @@ class Strgen
|
|
50
57
|
acc[type] = true
|
51
58
|
acc
|
52
59
|
end.tap do |hash|
|
53
|
-
hash
|
54
|
-
hash[:repeat] = true
|
60
|
+
hash.merge! length: 12, repeat: true
|
55
61
|
end.each do |method, default|
|
56
62
|
next unless send(method.to_sym).nil?
|
57
63
|
send("#{method}=".to_sym, default)
|
data/lib/strgen/version.rb
CHANGED
data/strgen.gemspec
CHANGED
@@ -21,6 +21,6 @@ Gem::Specification.new do |spec|
|
|
21
21
|
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.9"
|
23
23
|
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
-
spec.add_development_dependency "rspec
|
24
|
+
spec.add_development_dependency "rspec"
|
25
25
|
spec.add_development_dependency "pry"
|
26
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: strgen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Connor Atherton
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name: rspec
|
42
|
+
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|