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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0f962b94f3540b4ed7e8a9ecc77d1e1e7734fba9
4
- data.tar.gz: c161fee33122e89f8a32da00ddd1bd151d902e0f
3
+ metadata.gz: 0befb983c0d19506b16949c8b8d92bdae47e1d02
4
+ data.tar.gz: 5798aa417673efd9eae64c705d560c6dbd886d74
5
5
  SHA512:
6
- metadata.gz: 2866afcb8523555f6617e262c5a4922c2e67cf0ffd9c31cd47ec6b22930f48ce50b0b383d5621f7593f2319018b2f701f4762b6779d13c8323e631d6964a13c9
7
- data.tar.gz: b2a2983a97ca895afbaee0dba4e2adcb61ef585eaa2fc36ad820fabbf5c471d6a87b0967da2405a8827043aa2f5df6444dd3d1f392b247fccb3d6a8880f6c9cc
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-01'
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
@@ -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
@@ -0,0 +1,12 @@
1
+ module Kodo
2
+ module Algorithms
3
+ class Sha1 < Kodo::Algorithms::Base
4
+ def create
5
+ for i in 1..@count do
6
+ seed = DEFAULT_SEED_LIBRARY.base64
7
+ puts Digest::SHA1.hexdigest(seed)
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -2,3 +2,5 @@ require 'kodo/algorithms/base'
2
2
  require 'kodo/algorithms/md5'
3
3
  require 'kodo/algorithms/uuid'
4
4
  require 'kodo/algorithms/base64'
5
+ require 'kodo/algorithms/sha1'
6
+ require 'kodo/algorithms/random'
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(',')}"
@@ -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
 
@@ -4,4 +4,5 @@ module Kodo
4
4
 
5
5
  class ParameterNotFound < KodoException; end
6
6
  class AlgorithmNotFound < KodoException; end
7
+ class InvalidArgumentCombination < KodoException; end
7
8
  end
data/lib/kodo/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Kodo
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  GITHUB_REPO = 'https://github.com/hertzz/kodo'
4
4
  AUTHOR_NAME = ['Tom Johnson']
5
5
  AUTHOR_EMAIL = ['tom@thebitcrusher.net']
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.0
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-01 00:00:00.000000000 Z
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