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 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' ^ 'test' # => "\u0006\u0010\u0011\r\u0019\f\u0000\u0017"
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
 
@@ -32,7 +32,8 @@ module Rubymisc
32
32
  # rescue; raise NestedException, 'Error B'; end
33
33
  #
34
34
  class NestedException < StandardError
35
- attr_reader :original
35
+ attr :original
36
+
36
37
  def initialize(msg, original = $!)
37
38
  super(msg)
38
39
  @original = original
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- if defined?('ActiveRecord')
3
+ if defined?(ActiveRecord)
4
4
  module Rubymisc
5
5
  module ArValidates
6
6
  def validates_url(attribute = :url)
@@ -3,9 +3,11 @@
3
3
  module Rubymisc
4
4
  module String
5
5
  def ^(key)
6
- key_num = key.bytes.cycle
7
- bytes.map { |byte| byte ^ key_num.next }.pack('C*').force_encoding(self.encoding)
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
 
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Rubymisc
4
- VERSION = '0.0.3'
4
+ VERSION = '0.0.3.1'
5
5
  end
data/lib/rubymisc.rb CHANGED
@@ -7,6 +7,7 @@ require 'rubymisc/ext/object'
7
7
  require 'rubymisc/ext/integer'
8
8
  require 'rubymisc/ext/float'
9
9
  require 'rubymisc/ext/string'
10
+ require 'rubymisc/ext/active_record'
10
11
 
11
12
  require 'rubymisc/regex'
12
13
  require 'rubymisc/exceptional'
@@ -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
@@ -3,5 +3,5 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe Rubymisc::VERSION do
6
- it { should =~ /\A\d+\.\d+\.\d+\z/ }
6
+ it { should =~ /\A\d+\.\d+\.\d+(\.\d+)?\z/ }
7
7
  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-08 00:00:00.000000000 Z
12
+ date: 2011-12-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: :rspec