kodo 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +10 -0
- data/kodo.gemspec +1 -1
- data/lib/kodo/algorithms/base.rb +3 -2
- data/lib/kodo/algorithms/random.rb +17 -0
- data/lib/kodo/algorithms/sha1.rb +12 -0
- data/lib/kodo/algorithms.rb +2 -0
- data/lib/kodo/core/cli.rb +4 -0
- data/lib/kodo/core/generator.rb +17 -2
- data/lib/kodo/exceptions.rb +1 -0
- data/lib/kodo/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0befb983c0d19506b16949c8b8d92bdae47e1d02
|
4
|
+
data.tar.gz: 5798aa417673efd9eae64c705d560c6dbd886d74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6262f16cfa52b7ca7ca743571b211ffddcef8586cf224e70e9bbbae7dab45bafee4156442936746830de75faf0576b9ef983f039ce7fd0ee68aea0465e6675d3
|
7
|
+
data.tar.gz: 699cd2383716df1a15aff167748e78ecf1ced0c613f19541823305b8dd951031e95a67a30f162e638a1467708deb7963778f231841c1f8b3a90bd3be277e734c
|
data/README.md
CHANGED
@@ -9,6 +9,15 @@ $ gem install kodo
|
|
9
9
|
```
|
10
10
|
|
11
11
|
## Algorithms
|
12
|
+
#### Random
|
13
|
+
```shell
|
14
|
+
$ kodo -a random
|
15
|
+
ocj8=g[imQ`e\?Zu
|
16
|
+
|
17
|
+
$ kodo -a random -m 32
|
18
|
+
JCHeWIbnomFq=[RD\1r0_vE2hTVZXL<>
|
19
|
+
```
|
20
|
+
|
12
21
|
#### Base64
|
13
22
|
```shell
|
14
23
|
$ kodo -a base64
|
@@ -32,6 +41,7 @@ $ kodo -a md5
|
|
32
41
|
usage: kodo [OPTIONS]
|
33
42
|
-a, --algorithm TYPE Generation algorithm
|
34
43
|
-c, --count NUMBER Number of entries to generate
|
44
|
+
-m, --max-length SIZE Length of generated entries (random)
|
35
45
|
-v, --version Show version information
|
36
46
|
-h, --help Show this help menu
|
37
47
|
```
|
data/kodo.gemspec
CHANGED
@@ -6,7 +6,7 @@ require 'kodo/version'
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = 'kodo'
|
8
8
|
s.version = Kodo::VERSION
|
9
|
-
s.date = '2015-09-
|
9
|
+
s.date = '2015-09-03'
|
10
10
|
s.summary = 'Unique random generator'
|
11
11
|
s.description = 'Generates random strings/sequences using various algorithms'
|
12
12
|
s.authors = Kodo::AUTHOR_NAME
|
data/lib/kodo/algorithms/base.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
module Kodo
|
2
2
|
module Algorithms
|
3
3
|
class Base
|
4
|
-
attr_accessor :name, :seed, :count
|
4
|
+
attr_accessor :name, :seed, :count, :max_length
|
5
5
|
|
6
6
|
DEFAULT_SEED_LIBRARY = SecureRandom
|
7
7
|
|
8
|
-
def initialize(count)
|
8
|
+
def initialize(count, max_length)
|
9
9
|
self.count = count
|
10
|
+
self.max_length = max_length
|
10
11
|
end
|
11
12
|
|
12
13
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Kodo
|
2
|
+
module Algorithms
|
3
|
+
class Random < Kodo::Algorithms::Base
|
4
|
+
DEFAULT_LENGTH = 16
|
5
|
+
|
6
|
+
def create
|
7
|
+
if @max_length.nil?
|
8
|
+
@max_length = DEFAULT_LENGTH
|
9
|
+
end
|
10
|
+
|
11
|
+
for i in 1..@count do
|
12
|
+
puts ('0'..'z').to_a.shuffle.first(@max_length).join
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/kodo/algorithms.rb
CHANGED
data/lib/kodo/core/cli.rb
CHANGED
@@ -25,6 +25,10 @@ module Kodo
|
|
25
25
|
options.count = c
|
26
26
|
end
|
27
27
|
|
28
|
+
opts.on('-m', '--max-length SIZE', 'Length of generated entries (random)') do |m|
|
29
|
+
options.max_length = m
|
30
|
+
end
|
31
|
+
|
28
32
|
opts.on_tail('-v', '--version', 'Show version information') do
|
29
33
|
puts "kodo #{Kodo::VERSION}"
|
30
34
|
puts "Copyright (C) 2015 - #{Kodo::AUTHOR_NAME.join(',')}"
|
data/lib/kodo/core/generator.rb
CHANGED
@@ -1,12 +1,27 @@
|
|
1
1
|
module Kodo
|
2
2
|
class Generator
|
3
|
-
attr_reader :algorithm, :count
|
3
|
+
attr_reader :algorithm, :count, :max_length
|
4
4
|
|
5
5
|
DEFAULT_ALGORITHM = "md5"
|
6
6
|
|
7
7
|
def initialize(options=nil)
|
8
8
|
self.algorithm = options.algorithm
|
9
9
|
self.count = options.count
|
10
|
+
self.max_length = options.max_length
|
11
|
+
end
|
12
|
+
|
13
|
+
def max_length=(size=nil)
|
14
|
+
if !size.nil?
|
15
|
+
if @algorithm != Kodo::Algorithms::Random
|
16
|
+
raise Kodo::InvalidArgumentCombination, "Max length cannot be used for the #{@algorithm.name} algorithm"
|
17
|
+
end
|
18
|
+
|
19
|
+
if size.to_i >= 1 && size.to_i <= 512
|
20
|
+
@max_length = size.to_i
|
21
|
+
else
|
22
|
+
raise Exception, 'Max length must be greater than 1 and less than 512'
|
23
|
+
end
|
24
|
+
end
|
10
25
|
end
|
11
26
|
|
12
27
|
def algorithm=(type=nil)
|
@@ -36,7 +51,7 @@ module Kodo
|
|
36
51
|
end
|
37
52
|
|
38
53
|
def run
|
39
|
-
algorithm = @algorithm.new(@count)
|
54
|
+
algorithm = @algorithm.new(@count, @max_length)
|
40
55
|
algorithm.create
|
41
56
|
end
|
42
57
|
|
data/lib/kodo/exceptions.rb
CHANGED
data/lib/kodo/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kodo
|
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
|
- Tom Johnson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Generates random strings/sequences using various algorithms
|
14
14
|
email:
|
@@ -31,6 +31,8 @@ files:
|
|
31
31
|
- lib/kodo/algorithms/base.rb
|
32
32
|
- lib/kodo/algorithms/base64.rb
|
33
33
|
- lib/kodo/algorithms/md5.rb
|
34
|
+
- lib/kodo/algorithms/random.rb
|
35
|
+
- lib/kodo/algorithms/sha1.rb
|
34
36
|
- lib/kodo/algorithms/uuid.rb
|
35
37
|
- lib/kodo/core/cli.rb
|
36
38
|
- lib/kodo/core/generator.rb
|