matrext 0.4.0 → 0.4.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/bin/matrext +24 -2
- data/lib/matrext/core.rb +34 -5
- data/lib/matrext/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad81ebd8c28eece1ff22279fd06a5b18738d2552
|
4
|
+
data.tar.gz: 7bc7db5f76644217c39579c8452282f265348b43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d84768ac570bb61092f645347cf11384d02894f4816f05198e6c8269c27dcf678424f1eaf0468fadfb5219467ae4fa9fe05e0a12bbd0db1dbe97d834ae265947
|
7
|
+
data.tar.gz: ec78f1672a1ce7c3a07e9802c315d29772a63e8f58f00214ebd3ae086de2ff2e79b88e4f5f8abc6f4e84d9136abb69bfce8111ec37493058637c475a6f91b10f
|
data/bin/matrext
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'optparse'
|
4
|
+
require 'pry'
|
4
5
|
|
5
6
|
require_relative '../lib/matrext'
|
6
7
|
require_relative '../lib/matrext/version'
|
7
8
|
|
8
9
|
def parse_options
|
9
|
-
options = {:oneline => false, :speed => nil}
|
10
|
+
options = {:oneline => false, :speed => nil, :alpha => true, :numeric => true, :random => true}
|
10
11
|
|
11
12
|
optparse = OptionParser.new do |opts|
|
12
|
-
opts.banner = 'usage: matrext "phrase" [-o] [-s insane|fast|slow]'
|
13
|
+
opts.banner = 'usage: matrext "phrase" [-o] [-s insane|fast|slow] [-a true|false] [-n true|false] [-r true|false]'
|
13
14
|
|
14
15
|
opts.on('-s', '--speed SPEED', 'Speed at which the text decodes') do |speed|
|
15
16
|
options[:speed] = speed
|
@@ -19,6 +20,27 @@ def parse_options
|
|
19
20
|
options[:oneline] = true
|
20
21
|
end
|
21
22
|
|
23
|
+
opts.on('-a', '--alpha BOOLEAN', 'Whether to include alphabetical characters') do |alpha|
|
24
|
+
case alpha
|
25
|
+
when 'false', 'f'
|
26
|
+
options[:alpha] = false
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
opts.on('-n', '--numeric BOOLEAN', 'Whether to include numeric characters') do |numeric|
|
31
|
+
case numeric
|
32
|
+
when 'false', 'f'
|
33
|
+
options[:numeric] = false
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
opts.on('-r', '--random BOOLEAN', 'Whether to include non-alphanumeric random characters') do |random|
|
38
|
+
case random
|
39
|
+
when 'false', 'f'
|
40
|
+
options[:random] = false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
22
44
|
opts.on('-v', '--version', 'Display version number and exit') do
|
23
45
|
puts "#{$PROGRAM_NAME} #{Matrext::VERSION}"
|
24
46
|
exit
|
data/lib/matrext/core.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
# lib/matrext/core.rb
|
2
2
|
# The core processing unit
|
3
3
|
|
4
|
-
require 'pry'
|
5
|
-
|
6
4
|
module Matrext
|
7
|
-
CHAR_POOL = (33..126).map{ |i| i.chr }
|
8
5
|
NOISE_MIN_DEFAULT = 4
|
9
6
|
NOISE_MAX_DEFAULT = 6
|
10
7
|
DELAY_MIN_DEFAULT = 0.009
|
11
8
|
DELAY_MAX_DEFAULT = 0.012
|
12
9
|
|
10
|
+
attr_accessor :alpha_chars, :numeric_chars, :random_chars
|
11
|
+
|
13
12
|
def self.process(options)
|
13
|
+
character_pool = self.create_character_pool(options)
|
14
|
+
|
14
15
|
letters = options[:phrase]
|
15
16
|
|
16
17
|
unless options[:speed].nil?
|
@@ -43,9 +44,9 @@ module Matrext
|
|
43
44
|
letters.each_char do |l|
|
44
45
|
letter_noise = rand(noise_min..noise_max)
|
45
46
|
letter_delay = rand(delay_min..delay_max)
|
46
|
-
|
47
|
+
|
47
48
|
(0..letter_noise).each do |n|
|
48
|
-
print
|
49
|
+
print get_random_letter(character_pool)
|
49
50
|
sleep(letter_delay)
|
50
51
|
print "\b"
|
51
52
|
end
|
@@ -57,4 +58,32 @@ module Matrext
|
|
57
58
|
puts
|
58
59
|
end
|
59
60
|
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def self.alpha_chars
|
65
|
+
((65..90).map{|i| i.chr} | (97..122).map{|i| i.chr})
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.numeric_chars
|
69
|
+
(48..57).map{|i| i.chr}
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.random_chars
|
73
|
+
((33..47).map{|i| i.chr} | (91..96).map{|i| i.chr} | (123..126).map{|i| i.chr})
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.create_character_pool(options)
|
77
|
+
chars = []
|
78
|
+
|
79
|
+
chars = chars | alpha_chars if options.fetch(:alpha)
|
80
|
+
chars = chars | numeric_chars if options.fetch(:numeric)
|
81
|
+
chars = chars | random_chars if options.fetch(:random)
|
82
|
+
|
83
|
+
return chars
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.get_random_letter(chars)
|
87
|
+
chars[rand(0..chars.length-1)]
|
88
|
+
end
|
60
89
|
end
|
data/lib/matrext/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: matrext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Chadwick
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|