simplescrambler 0.0.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 +7 -0
- data/lib/exceptions.rb +59 -0
- data/lib/simplescrambler.rb +115 -0
- metadata +46 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 0e4d7ed74075d60a7fbba22c1f64934e07c9ec72
|
|
4
|
+
data.tar.gz: 45d7bce860261788cf8199fc12f37767cd546e03
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 99469ace9e6b163e2c3df788daf867a7d4290f9371013fbd5d1182c32de273850106bc8b6d29ec40161965db80d237776416250af8788ba6f92fadfc72ac711c
|
|
7
|
+
data.tar.gz: 3cbfd546a1fc101a46e80a5009a26de64706761c13d39a9062e11b4d805e60bcb308015370ebea715ebb5ba32e66eae24bfd0eb61e2cd497f2ce570641203891
|
data/lib/exceptions.rb
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
class TooSmall < StandardError
|
|
2
|
+
def initialize(msg = "Number is too small!")
|
|
3
|
+
super
|
|
4
|
+
end
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
class MinMaxMismatch < StandardError
|
|
8
|
+
def initialize(msg = "Max is smaller than Min!")
|
|
9
|
+
super
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class NotNumber < StandardError
|
|
14
|
+
def initialize(msg = "Input is not an integer!")
|
|
15
|
+
super
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class NotString < StandardError
|
|
20
|
+
def initialize(msg = "Input is not a string!")
|
|
21
|
+
super
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
class CannotScrambleStringLetter < StandardError
|
|
26
|
+
def initialize(msg = "Input cannot have only one letter!")
|
|
27
|
+
super
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
class CannotScrambleStringSame < StandardError
|
|
32
|
+
def initialize(msg = "Input must have at least two unique letters!")
|
|
33
|
+
super
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
class CannotScrambleNumberDigit < StandardError
|
|
38
|
+
def initialize(msg = "Input cannot have only one digit!")
|
|
39
|
+
super
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
class CannotScrambleNumberSame < StandardError
|
|
44
|
+
def initialize(msg = "Input must have at least two unique digits!")
|
|
45
|
+
super
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
class CannotScrambleArrayElement < StandardError
|
|
50
|
+
def initialize(msg = "Input cannot have only one element!")
|
|
51
|
+
super
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
class CannotScrambleArraySame < StandardError
|
|
56
|
+
def initialize(msg = "Input must have at least two unique elements!")
|
|
57
|
+
super
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
require_relative 'exceptions'
|
|
2
|
+
|
|
3
|
+
class String
|
|
4
|
+
def scramble(min = 10, max = 100)
|
|
5
|
+
if max.class != Integer || min.class != Integer
|
|
6
|
+
raise NotNumber
|
|
7
|
+
elsif self.length == 1
|
|
8
|
+
raise CannotScrambleStringLetter
|
|
9
|
+
elsif self.chars.count(self.chars[0]) == self.length
|
|
10
|
+
raise CannotScrambleStringSame
|
|
11
|
+
elsif min > 0 && max >= min
|
|
12
|
+
temp = self.chars
|
|
13
|
+
(min + rand(max - min + 1)).times do
|
|
14
|
+
random = rand(temp.length)
|
|
15
|
+
random2 = rand(temp.length)
|
|
16
|
+
if random2 == random
|
|
17
|
+
until random2 != random
|
|
18
|
+
random2 = rand(temp.length)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
onepos = random
|
|
22
|
+
random = temp[random]
|
|
23
|
+
twopos = random2
|
|
24
|
+
random2 = temp[random2]
|
|
25
|
+
temp[onepos] = random2
|
|
26
|
+
temp[twopos] = random
|
|
27
|
+
end
|
|
28
|
+
return temp.join
|
|
29
|
+
elsif min <= 0
|
|
30
|
+
raise TooSmall
|
|
31
|
+
elsif max < min
|
|
32
|
+
raise MinMaxMismatch
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def isanagram?(base)
|
|
37
|
+
if base.class != String
|
|
38
|
+
raise NotString
|
|
39
|
+
else
|
|
40
|
+
one = self.chars
|
|
41
|
+
two = base.chars
|
|
42
|
+
if one.sort == two.sort
|
|
43
|
+
return true
|
|
44
|
+
else
|
|
45
|
+
return false
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
class Integer
|
|
52
|
+
def scramble(min = 10, max = 100)
|
|
53
|
+
if self.to_s.length == 1
|
|
54
|
+
raise CannotScrambleNumberDigit
|
|
55
|
+
elsif self.to_s.chars.count(self.to_s.chars[0]) == self.to_s.length
|
|
56
|
+
raise CannotScrambleNumberSame
|
|
57
|
+
elsif max.class != Integer || min.class != Integer
|
|
58
|
+
raise NotNumber
|
|
59
|
+
else
|
|
60
|
+
return self.to_s.scramble(min, max).to_i
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
class Float
|
|
66
|
+
def scramble(min = 10, max = 100)
|
|
67
|
+
if self.to_s.length == 1
|
|
68
|
+
raise CannotScrambleNumberDigit
|
|
69
|
+
elsif self.to_s.chars.count(self.to_s.chars[0]) == self.to_s.length
|
|
70
|
+
raise CannotScrambleNumberSame
|
|
71
|
+
elsif max.class != Integer || min.class != Integer
|
|
72
|
+
raise NotNumber
|
|
73
|
+
else
|
|
74
|
+
temp = self.to_s.chars
|
|
75
|
+
temp.delete(".")
|
|
76
|
+
temp = temp.join.scramble(min, max).chars
|
|
77
|
+
temp.insert((1 + rand(temp.length - 1)), ".")
|
|
78
|
+
return temp.join.to_f
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
class Array
|
|
84
|
+
def scramble(min = 10, max = 100)
|
|
85
|
+
if max.class != Integer || min.class != Integer
|
|
86
|
+
raise NotNumber
|
|
87
|
+
elsif self.length == 1
|
|
88
|
+
raise CannotScrambleArrayElement
|
|
89
|
+
elsif self.count(self[0]) == self.length
|
|
90
|
+
raise CannotScrambleArraySame
|
|
91
|
+
elsif min > 0 && max >= min
|
|
92
|
+
temp = self
|
|
93
|
+
(min + rand(max - min + 1)).times do
|
|
94
|
+
random = rand(temp.length)
|
|
95
|
+
random2 = rand(temp.length)
|
|
96
|
+
if random2 == random
|
|
97
|
+
until random2 != random
|
|
98
|
+
random2 = rand(temp.length)
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
onepos = random
|
|
102
|
+
random = temp[random]
|
|
103
|
+
twopos = random2
|
|
104
|
+
random2 = temp[random2]
|
|
105
|
+
temp[onepos] = random2
|
|
106
|
+
temp[twopos] = random
|
|
107
|
+
end
|
|
108
|
+
return temp
|
|
109
|
+
elsif min <= 0
|
|
110
|
+
raise TooSmall
|
|
111
|
+
elsif max < min
|
|
112
|
+
raise MinMaxMismatch
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: simplescrambler
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Jonathan Tan
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-05-19 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: A simple scrambler for strings, integers, floats and arrays. Number of
|
|
14
|
+
scrambles can be specified.
|
|
15
|
+
email: jonathantanatlol@gmail.com
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- lib/exceptions.rb
|
|
21
|
+
- lib/simplescrambler.rb
|
|
22
|
+
homepage: https://github.com/peaceknight05/simplescrambler
|
|
23
|
+
licenses:
|
|
24
|
+
- MIT
|
|
25
|
+
metadata: {}
|
|
26
|
+
post_install_message:
|
|
27
|
+
rdoc_options: []
|
|
28
|
+
require_paths:
|
|
29
|
+
- lib
|
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
31
|
+
requirements:
|
|
32
|
+
- - ">="
|
|
33
|
+
- !ruby/object:Gem::Version
|
|
34
|
+
version: '0'
|
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
40
|
+
requirements: []
|
|
41
|
+
rubyforge_project:
|
|
42
|
+
rubygems_version: 2.6.14
|
|
43
|
+
signing_key:
|
|
44
|
+
specification_version: 4
|
|
45
|
+
summary: A simple scrambler for strings, integers, floats and arrays.
|
|
46
|
+
test_files: []
|