rubymisc 0.0.3 → 0.0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +3 -3
- data/lib/rubymisc/exceptional.rb +2 -1
- data/lib/rubymisc/ext/active_record.rb +1 -1
- data/lib/rubymisc/ext/string.rb +4 -2
- data/lib/rubymisc/version.rb +1 -1
- data/lib/rubymisc.rb +1 -0
- data/spec/rubymisc/ext/string_spec.rb +18 -0
- data/spec/rubymisc/version_spec.rb +1 -1
- metadata +2 -2
data/README
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
1 What is Rubymisc (Ruby miscellaneous | /ˈru:bi ˌmisəˈleiniəs/)
|
2
|
-
Miscellaneous and humble tool-set of useful Ruby
|
2
|
+
Miscellaneous and humble tool-set of useful Ruby (RUBY_VERSION >= 1.9.3)
|
3
3
|
|
4
4
|
1.1 Installation
|
5
5
|
gem install rubymisc
|
@@ -36,8 +36,8 @@
|
|
36
36
|
|
37
37
|
2.4 String
|
38
38
|
|
39
|
-
|
40
|
-
e13: 'rubymisc'
|
39
|
+
#^, #xor
|
40
|
+
e13: 'rubymisc'.xor 'test' # => "\u0006\u0010\u0011\r\u0019\f\u0000\u0017"
|
41
41
|
|
42
42
|
2.5 ActiveRecord::Base
|
43
43
|
|
data/lib/rubymisc/exceptional.rb
CHANGED
data/lib/rubymisc/ext/string.rb
CHANGED
@@ -3,9 +3,11 @@
|
|
3
3
|
module Rubymisc
|
4
4
|
module String
|
5
5
|
def ^(key)
|
6
|
-
|
7
|
-
|
6
|
+
key_bytes = key.bytes.cycle
|
7
|
+
xor_proc = ->(byte) { byte ^ key_bytes.next }
|
8
|
+
bytes.map(&xor_proc).pack('C*').force_encoding(self.encoding)
|
8
9
|
end
|
10
|
+
alias_method :xor, :^
|
9
11
|
end
|
10
12
|
end
|
11
13
|
|
data/lib/rubymisc/version.rb
CHANGED
data/lib/rubymisc.rb
CHANGED
@@ -12,6 +12,24 @@ describe Rubymisc::String do
|
|
12
12
|
test_string.should_not == test_string ^ example.metadata[:string_key]
|
13
13
|
test_string.should == test_string ^ example.metadata[:string_key] ^ example.metadata[:string_key]
|
14
14
|
end
|
15
|
+
|
16
|
+
specify 'return certain value' do
|
17
|
+
(test_string ^ example.metadata[:string_key]).should == "\u0006\u0010\u0011\r\u0019\f\u0000\u0017"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#xor' do
|
23
|
+
context 'alias for ^', :string_key => 'test' do
|
24
|
+
specify "returns the result of xor operation between the receiver's bytes and the string_key's bytes" do
|
25
|
+
test_string.should respond_to(:xor)
|
26
|
+
test_string.should_not == test_string.xor(example.metadata[:string_key])
|
27
|
+
test_string.should == test_string.xor(example.metadata[:string_key]).xor(example.metadata[:string_key])
|
28
|
+
end
|
29
|
+
|
30
|
+
specify 'return certain value' do
|
31
|
+
(test_string.xor(example.metadata[:string_key])).should == "\u0006\u0010\u0011\r\u0019\f\u0000\u0017"
|
32
|
+
end
|
15
33
|
end
|
16
34
|
end
|
17
35
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubymisc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.3
|
4
|
+
version: 0.0.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-12-
|
12
|
+
date: 2011-12-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: :rspec
|