kodo 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0f962b94f3540b4ed7e8a9ecc77d1e1e7734fba9
4
+ data.tar.gz: c161fee33122e89f8a32da00ddd1bd151d902e0f
5
+ SHA512:
6
+ metadata.gz: 2866afcb8523555f6617e262c5a4922c2e67cf0ffd9c31cd47ec6b22930f48ce50b0b383d5621f7593f2319018b2f701f4762b6779d13c8323e631d6964a13c9
7
+ data.tar.gz: b2a2983a97ca895afbaee0dba4e2adcb61ef585eaa2fc36ad820fabbf5c471d6a87b0967da2405a8827043aa2f5df6444dd3d1f392b247fccb3d6a8880f6c9cc
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/CONTRIBUTORS.md ADDED
@@ -0,0 +1 @@
1
+ * Tom Johnson <<tom@thebitcrusher.net>>
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :development do
4
+ gem 'rspec'
5
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,26 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.2.5)
5
+ rspec (3.3.0)
6
+ rspec-core (~> 3.3.0)
7
+ rspec-expectations (~> 3.3.0)
8
+ rspec-mocks (~> 3.3.0)
9
+ rspec-core (3.3.2)
10
+ rspec-support (~> 3.3.0)
11
+ rspec-expectations (3.3.1)
12
+ diff-lcs (>= 1.2.0, < 2.0)
13
+ rspec-support (~> 3.3.0)
14
+ rspec-mocks (3.3.2)
15
+ diff-lcs (>= 1.2.0, < 2.0)
16
+ rspec-support (~> 3.3.0)
17
+ rspec-support (3.3.0)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ rspec
24
+
25
+ BUNDLED WITH
26
+ 1.10.6
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 [CONTRIBUTORS.md](CONTRIBUTORS.md)
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.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Kodo
2
+ Kodo is a generator which utilizes various algorithms such as `MD5` and `base64` to simplify creation
3
+ of random strings and sequences.
4
+
5
+ ## Installation
6
+ Download the gem from rubygems:
7
+ ```shell
8
+ $ gem install kodo
9
+ ```
10
+
11
+ ## Algorithms
12
+ #### Base64
13
+ ```shell
14
+ $ kodo -a base64
15
+ QfF9SJq9V_SPnvMtnSut2Q==
16
+ ```
17
+
18
+ #### UUID
19
+ ```shell
20
+ $ kodo -a uuid
21
+ 2aa2ebca-3116-4e91-884c-73e92710273c
22
+ ```
23
+
24
+ #### MD5
25
+ ```shell
26
+ $ kodo -a md5
27
+ 691e5bce9c3f6c45a4dc18f6261d5715
28
+ ```
29
+
30
+ ## Usage
31
+ ```shell
32
+ usage: kodo [OPTIONS]
33
+ -a, --algorithm TYPE Generation algorithm
34
+ -c, --count NUMBER Number of entries to generate
35
+ -v, --version Show version information
36
+ -h, --help Show this help menu
37
+ ```
38
+
39
+ ## Contributors
40
+ Please refer to [CONTRIBUTORS.md](CONTRIBUTORS.md)
41
+
42
+ ## License
43
+ Please refer to [LICENSE.md](LICENSE.md)
data/bin/kodo ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Kodo
4
+ # https://github.com/hertzz/kodo
5
+ #
6
+
7
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'kodo'))
8
+ Kodo::CLI.run(ARGV)
data/kodo.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require 'kodo/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'kodo'
8
+ s.version = Kodo::VERSION
9
+ s.date = '2015-09-01'
10
+ s.summary = 'Unique random generator'
11
+ s.description = 'Generates random strings/sequences using various algorithms'
12
+ s.authors = Kodo::AUTHOR_NAME
13
+ s.email = Kodo::AUTHOR_EMAIL
14
+ s.homepage = 'https://github.com/hertzz/kodo'
15
+ s.license = 'MIT'
16
+ s.require_paths = %w[lib]
17
+ s.executables = ["kodo"]
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {spec,tests}/*`.split("\n")
20
+ end
data/lib/kodo.rb ADDED
@@ -0,0 +1,13 @@
1
+ __LIB_DIR__ = File.expand_path(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift __LIB_DIR__ unless $LOAD_PATH.include?(__LIB_DIR__)
3
+
4
+ # Stdlib includes
5
+ require 'yaml'
6
+ require 'securerandom'
7
+
8
+ # Internal includes
9
+ require 'kodo/version'
10
+ require 'kodo/exceptions'
11
+ require 'kodo/core/cli'
12
+ require 'kodo/core/generator'
13
+ require 'kodo/algorithms'
@@ -0,0 +1,4 @@
1
+ require 'kodo/algorithms/base'
2
+ require 'kodo/algorithms/md5'
3
+ require 'kodo/algorithms/uuid'
4
+ require 'kodo/algorithms/base64'
@@ -0,0 +1,14 @@
1
+ module Kodo
2
+ module Algorithms
3
+ class Base
4
+ attr_accessor :name, :seed, :count
5
+
6
+ DEFAULT_SEED_LIBRARY = SecureRandom
7
+
8
+ def initialize(count)
9
+ self.count = count
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ module Kodo
2
+ module Algorithms
3
+ class Base64 < Kodo::Algorithms::Base
4
+ def create
5
+ for i in 1..@count do
6
+ puts SecureRandom.urlsafe_base64(nil, true)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ module Kodo
2
+ module Algorithms
3
+ class Md5 < Kodo::Algorithms::Base
4
+ def create
5
+ for i in 1..@count do
6
+ seed = DEFAULT_SEED_LIBRARY.base64
7
+ puts Digest::MD5.hexdigest(seed)
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ module Kodo
2
+ module Algorithms
3
+ class Uuid < Kodo::Algorithms::Base
4
+ def create
5
+ for i in 1..@count do
6
+ puts SecureRandom.uuid()
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,43 @@
1
+ require 'optparse'
2
+ require 'ostruct'
3
+
4
+ module Kodo
5
+ class CLI
6
+ def self.run(args)
7
+ options = parse(args)
8
+ generator = Kodo::Generator.new(options)
9
+ generator.run
10
+ end
11
+
12
+ private
13
+
14
+ def self.parse(args)
15
+ options = OpenStruct.new
16
+
17
+ parser = OptionParser.new do |opts|
18
+ opts.banner = 'usage: kodo [OPTIONS]'
19
+
20
+ opts.on('-a', '--algorithm TYPE', 'Generation algorithm') do |a|
21
+ options.algorithm = a
22
+ end
23
+
24
+ opts.on('-c', '--count NUMBER', 'Number of entries to generate') do |c|
25
+ options.count = c
26
+ end
27
+
28
+ opts.on_tail('-v', '--version', 'Show version information') do
29
+ puts "kodo #{Kodo::VERSION}"
30
+ puts "Copyright (C) 2015 - #{Kodo::AUTHOR_NAME.join(',')}"
31
+ exit(0)
32
+ end
33
+
34
+ opts.on_tail('-h', '--help', 'Show this help menu') do
35
+ puts opts
36
+ exit(0)
37
+ end
38
+ end.parse!
39
+
40
+ return options
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,44 @@
1
+ module Kodo
2
+ class Generator
3
+ attr_reader :algorithm, :count
4
+
5
+ DEFAULT_ALGORITHM = "md5"
6
+
7
+ def initialize(options=nil)
8
+ self.algorithm = options.algorithm
9
+ self.count = options.count
10
+ end
11
+
12
+ def algorithm=(type=nil)
13
+ if type.nil?
14
+ self.algorithm = DEFAULT_ALGORITHM
15
+ else
16
+ begin
17
+ if !Object.const_defined?("Kodo::Algorithms::#{type.capitalize}")
18
+ raise Kodo::AlgorithmNotFound, "\"#{type}\" is not a valid algorithm."
19
+ end
20
+
21
+ algorithm = Object.const_get("Kodo::Algorithms::#{type.capitalize}")
22
+ rescue Exception => e
23
+ raise e, "Failed to reference algorithm \"#{type.capitalize}\" - #{e.message}"
24
+ end
25
+
26
+ @algorithm = algorithm
27
+ end
28
+ end
29
+
30
+ def count=(number=1)
31
+ if number.nil?
32
+ number = 1
33
+ end
34
+
35
+ @count = number.to_i
36
+ end
37
+
38
+ def run
39
+ algorithm = @algorithm.new(@count)
40
+ algorithm.create
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,7 @@
1
+ module Kodo
2
+ class KodoException < StandardError
3
+ end
4
+
5
+ class ParameterNotFound < KodoException; end
6
+ class AlgorithmNotFound < KodoException; end
7
+ end
@@ -0,0 +1,6 @@
1
+ module Kodo
2
+ VERSION = '0.1.0'
3
+ GITHUB_REPO = 'https://github.com/hertzz/kodo'
4
+ AUTHOR_NAME = ['Tom Johnson']
5
+ AUTHOR_EMAIL = ['tom@thebitcrusher.net']
6
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kodo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tom Johnson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-01 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Generates random strings/sequences using various algorithms
14
+ email:
15
+ - tom@thebitcrusher.net
16
+ executables:
17
+ - kodo
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".gitignore"
22
+ - CONTRIBUTORS.md
23
+ - Gemfile
24
+ - Gemfile.lock
25
+ - LICENSE.md
26
+ - README.md
27
+ - bin/kodo
28
+ - kodo.gemspec
29
+ - lib/kodo.rb
30
+ - lib/kodo/algorithms.rb
31
+ - lib/kodo/algorithms/base.rb
32
+ - lib/kodo/algorithms/base64.rb
33
+ - lib/kodo/algorithms/md5.rb
34
+ - lib/kodo/algorithms/uuid.rb
35
+ - lib/kodo/core/cli.rb
36
+ - lib/kodo/core/generator.rb
37
+ - lib/kodo/exceptions.rb
38
+ - lib/kodo/version.rb
39
+ homepage: https://github.com/hertzz/kodo
40
+ licenses:
41
+ - MIT
42
+ metadata: {}
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubyforge_project:
59
+ rubygems_version: 2.4.5.1
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: Unique random generator
63
+ test_files: []