rubymisc 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/.rvmrc +1 -0
- data/Gemfile +2 -0
- data/README +43 -0
- data/Rakefile +13 -0
- data/lib/rubymisc/exceptional.rb +44 -0
- data/lib/rubymisc/ext/active_record.rb +28 -0
- data/lib/rubymisc/ext/float.rb +11 -0
- data/lib/rubymisc/ext/integer.rb +11 -0
- data/lib/rubymisc/ext/object.rb +23 -0
- data/lib/rubymisc/regex/manual.rb +39 -0
- data/lib/rubymisc/regex.rb +47 -0
- data/lib/rubymisc/version.rb +5 -0
- data/lib/rubymisc.rb +12 -0
- data/rubymisc.gemspec +30 -0
- data/spec/rubymisc/exceptional_spec.rb +50 -0
- data/spec/rubymisc/ext/float_spec.rb +17 -0
- data/spec/rubymisc/ext/integer_spec.rb +17 -0
- data/spec/rubymisc/ext/object_spec.rb +38 -0
- data/spec/rubymisc/regex/manual_spec.rb +26 -0
- data/spec/rubymisc/regex_spec.rb +67 -0
- data/spec/rubymisc/version_spec.rb +7 -0
- data/spec/rubymisc_spec.rb +6 -0
- data/spec/spec.rake +17 -0
- data/spec/spec_helper.rb +23 -0
- metadata +124 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.9.3@rubymisc 2>/dev/null
|
data/Gemfile
ADDED
data/README
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
1 What is Rubymisc (Ruby miscellaneous | /ˈru:bi ˌmisəˈleiniəs/)
|
2
|
+
Miscellaneous and humble tool-set of useful Ruby
|
3
|
+
|
4
|
+
1.1 Installation
|
5
|
+
gem install rubymisc
|
6
|
+
|
7
|
+
2 Usage
|
8
|
+
|
9
|
+
2.1 Regular expressions
|
10
|
+
e1: Rubymisc::Regex.email
|
11
|
+
e2: Rubymisc::Regex.url
|
12
|
+
e3: Rubymisc::Regex.zip
|
13
|
+
e4: Rubymisc::Regex.ipv4
|
14
|
+
e5: Rubymisc::Regex.mac_address
|
15
|
+
e6: Rubymisc::Regex.hexcode
|
16
|
+
e7: Rubymisc::Regex.usd
|
17
|
+
|
18
|
+
2.2 Object
|
19
|
+
|
20
|
+
#in?
|
21
|
+
e8: 100.in?([1, 2, 3, 4, 5, 100]) # => true
|
22
|
+
|
23
|
+
#not functor
|
24
|
+
e9: 100.not.instance_of?(Fixnum) # => false
|
25
|
+
|
26
|
+
#errors_with_message
|
27
|
+
e10: begin; raise 'Timeout socket'; rescue errors_with_message(/socket/); p 'socket E'; end
|
28
|
+
|
29
|
+
2.3 Integer
|
30
|
+
|
31
|
+
#percent_of
|
32
|
+
e11: 50.percent_of(100) # => 50.0
|
33
|
+
|
34
|
+
2.4 ActiveRecord::Base
|
35
|
+
.validates_url
|
36
|
+
.validates_email
|
37
|
+
.validates_image_url
|
38
|
+
|
39
|
+
3 Development
|
40
|
+
|
41
|
+
- `gem install bundler`
|
42
|
+
- `bundle install`
|
43
|
+
- `bundle exec rake spec`
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rake'
|
4
|
+
require 'bundler'
|
5
|
+
|
6
|
+
Bundler::GemHelper.install_tasks
|
7
|
+
|
8
|
+
Dir['lib/tasks/**/*.rake'].
|
9
|
+
concat(Dir['tasks/**/*.rake']).
|
10
|
+
concat(Dir['{test,spec}/*.rake']).each { |rake| load(rake) }
|
11
|
+
|
12
|
+
task :default => :spec
|
13
|
+
task :test => :spec # for http://test.rubygems.org/
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Rubymisc
|
4
|
+
module Exceptional
|
5
|
+
def ASSERT(&block)
|
6
|
+
begin
|
7
|
+
yield
|
8
|
+
rescue StandardError => e
|
9
|
+
STDERR.puts e.inspect
|
10
|
+
STDERR.puts e.backtrace
|
11
|
+
raise RuntimeError, "#{e.message}", caller
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
##
|
16
|
+
# @example
|
17
|
+
# begin; raise 'Timeout socket'; rescue errors_with_message(/socket/); p 'socket E'; end
|
18
|
+
#
|
19
|
+
def errors_with_message(pattern)
|
20
|
+
m = Module.new
|
21
|
+
(class << m; self; end).instance_eval do
|
22
|
+
define_method(:===) do |e|
|
23
|
+
pattern === e.message
|
24
|
+
end
|
25
|
+
end
|
26
|
+
m
|
27
|
+
end
|
28
|
+
|
29
|
+
##
|
30
|
+
# @example
|
31
|
+
# rescue => e; raise NestedException.new('Error B', e); end
|
32
|
+
# rescue; raise NestedException, 'Error B'; end
|
33
|
+
#
|
34
|
+
class NestedException < StandardError
|
35
|
+
attr_reader :original
|
36
|
+
def initialize(msg, original = $!)
|
37
|
+
super(msg)
|
38
|
+
@original = original
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
::Object.module_eval 'include Rubymisc::Exceptional'
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
if defined?('ActiveRecord')
|
4
|
+
module Rubymisc
|
5
|
+
module ArValidates
|
6
|
+
def validates_url(attribute = :url)
|
7
|
+
validates_presence_of attribute
|
8
|
+
validates_length_of attribute, :minimum => 12
|
9
|
+
validates_format_of attribute, :with => Regex.url, :message => %/isn't a valid URL./
|
10
|
+
end
|
11
|
+
|
12
|
+
def validates_email(attribute = :email)
|
13
|
+
validates_presence_of attribute
|
14
|
+
validates_length_of attribute, :minimum => 5
|
15
|
+
validates_format_of attribute, :with => Regex.email, :message => %/isn't a valid email./
|
16
|
+
end
|
17
|
+
|
18
|
+
def validates_image_url(attribute = :image_url)
|
19
|
+
validates attribute, allow_blank: true, format: {
|
20
|
+
with: %r{\.(gif|jpg|png)$}i,
|
21
|
+
message: 'must be a URL for GIF, JPG or PNG image.'
|
22
|
+
}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
ActiveRecord::Base.extend ArValidates
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Rubymisc
|
4
|
+
module Object
|
5
|
+
def in?(collection)
|
6
|
+
collection.respond_to?(:include?) ? collection.include?(self) : false
|
7
|
+
end
|
8
|
+
|
9
|
+
def not
|
10
|
+
not_functor = lambda { |op, *a, &b| !self.__send__(op, *a, &b) }
|
11
|
+
|
12
|
+
not_functor.singleton_class.module_eval <<-CODE
|
13
|
+
def method_missing(method, *arguments, &block)
|
14
|
+
call(method, *arguments, &block)
|
15
|
+
end
|
16
|
+
CODE
|
17
|
+
|
18
|
+
not_functor
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
::Object.module_eval 'include Rubymisc::Object'
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Rubymisc
|
4
|
+
module Regex
|
5
|
+
class Manual
|
6
|
+
def self.man
|
7
|
+
<<-EOS
|
8
|
+
Ruby character representations
|
9
|
+
------------------------------
|
10
|
+
Sequence Meaning
|
11
|
+
\\a Alert (bell), \\x07.
|
12
|
+
\\b Backspace, \\x08, supported only in character class.
|
13
|
+
\\e ESC character, \\x1B.
|
14
|
+
\\n Newline, \\x0A.
|
15
|
+
\\r Carriage return, \\x0D.
|
16
|
+
\\f Form feed, \\x0C.
|
17
|
+
\\t Horizontal tab \\x09.
|
18
|
+
\\v Vertical tab, \\x0B.
|
19
|
+
\\0octal Character specified by a two-digit octal code.
|
20
|
+
\\xhex Character specified by a two-digit hexadecimal code.
|
21
|
+
\\cchar Named control character.
|
22
|
+
|
23
|
+
Ruby character classses and class-like constructs
|
24
|
+
-------------------------------------------------
|
25
|
+
Class Meaning
|
26
|
+
[...] A single character listed, or contained within a listed range.
|
27
|
+
[^...] A single character not listed, and not contained within a listed range.
|
28
|
+
. Any character, except a line terminator (unless single-line mode, s).
|
29
|
+
\\w Word character.
|
30
|
+
\\W Nonword character.
|
31
|
+
\\d Digit.
|
32
|
+
\\D Nondigit.
|
33
|
+
\\s Whitespace character, [\\f\\n\\r\\t\\v].
|
34
|
+
\\S Nonwhitespace character, [^\\f\\n\\r\\t\\v].
|
35
|
+
EOS
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Rubymisc
|
4
|
+
module Regex
|
5
|
+
autoload :Manual, File.expand_path('../regex/manual', __FILE__)
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def email
|
9
|
+
email_name_regex = '[\w\.%\+\-]+'.freeze
|
10
|
+
domain_head_regex = '(?:[A-Z0-9\-]+\.)+'.freeze
|
11
|
+
domain_tld_regex = '(?:[A-Z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|jobs|museum)'.freeze
|
12
|
+
/\A#{email_name_regex}@#{domain_head_regex}#{domain_tld_regex}\z/i
|
13
|
+
end
|
14
|
+
|
15
|
+
def url
|
16
|
+
/\A((https?):(([A-Za-z0-9$_.+!*(),;\/?:@&~=-])|%[A-Za-z0-9]{2}){2,}(#([a-zA-Z0-9][a-zA-Z0-9$_.+!*(),;\/?:@&~=%-]*))?([A-Za-z0-9$_+!*();\/?:~-]))\z/
|
17
|
+
end
|
18
|
+
|
19
|
+
def zip
|
20
|
+
/\A\d{5}(?:-\d{4})?\z/
|
21
|
+
end
|
22
|
+
|
23
|
+
def ipv4
|
24
|
+
ip_octet = '(\d|[01]?\d\d|2[0-4]\d|25[0-5])'.freeze
|
25
|
+
/\A#{ip_octet}\.#{ip_octet}\.#{ip_octet}\.#{ip_octet}\z/
|
26
|
+
end
|
27
|
+
|
28
|
+
def mac_address
|
29
|
+
/\A(\h{2}:){5}\h{2}\z/
|
30
|
+
end
|
31
|
+
|
32
|
+
def hexcode
|
33
|
+
/\A#(\h{3})\1?\z/
|
34
|
+
end
|
35
|
+
|
36
|
+
def usd
|
37
|
+
/\A\$(\d{1,3}(\,\d{3})*|\d+)(\.\d{2})?\z/
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
code = <<-CODE
|
42
|
+
def man; Manual.man; end
|
43
|
+
CODE
|
44
|
+
|
45
|
+
singleton_class.module_eval code
|
46
|
+
end
|
47
|
+
end
|
data/lib/rubymisc.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Rubymisc
|
4
|
+
autoload :Object, 'rubymisc/ext/object'
|
5
|
+
autoload :Integer, 'rubymisc/ext/integer'
|
6
|
+
autoload :Float, 'rubymisc/ext/float'
|
7
|
+
|
8
|
+
autoload :Regex, 'rubymisc/regex'
|
9
|
+
autoload :Exceptional, 'rubymisc/exceptional'
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'rubymisc/version'
|
data/rubymisc.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
$:.push File.expand_path('../lib', __FILE__)
|
4
|
+
require 'rubymisc/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'rubymisc'
|
8
|
+
s.version = Rubymisc::VERSION
|
9
|
+
s.platform = Gem::Platform::RUBY
|
10
|
+
s.authors = ['Ivan Povalyukhin']
|
11
|
+
s.email = ['ipoval@ya.ru']
|
12
|
+
s.homepage = 'https://github.com/ipoval/rubymisc'
|
13
|
+
s.summary = %q{Ruby miscellaneous.}
|
14
|
+
s.description = %q{Miscellaneous and humble tool-set of useful Ruby.}
|
15
|
+
|
16
|
+
s.rubyforge_project = 'rubymisc'
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.require_paths = ['lib']
|
22
|
+
|
23
|
+
s.required_ruby_version = '>= 1.9.3'
|
24
|
+
s.required_rubygems_version = '>= 1.3.5'
|
25
|
+
|
26
|
+
{ rspec: '~> 2.8.0.rc1',
|
27
|
+
rake: '~> 0.9.2',
|
28
|
+
bundler: '~> 1.0.21',
|
29
|
+
simplecov: '~> 0.5.4' }.each { |lib, v| s.add_development_dependency lib, v }
|
30
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Rubymisc::Exceptional do
|
6
|
+
describe '#ASSERT' do
|
7
|
+
specify 'catches failing block and raises RuntimeError' do
|
8
|
+
failing_proc = -> { fail 'Fail message!' }
|
9
|
+
expect { ASSERT &failing_proc }.to raise_error RuntimeError
|
10
|
+
end
|
11
|
+
|
12
|
+
specify 'ok block does not raise error' do
|
13
|
+
success_proc = -> { true }
|
14
|
+
expect { ASSERT &success_proc }.to_not raise_error
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#errors_with_message' do
|
19
|
+
specify 'rescue an exception if message match' do
|
20
|
+
e_socket = -> {
|
21
|
+
begin; fail 'Timeout socket'; rescue errors_with_message(/socket/); end
|
22
|
+
}
|
23
|
+
expect(&e_socket).to_not raise_exception
|
24
|
+
end
|
25
|
+
|
26
|
+
specify 'do not rescue an exception if no message match' do
|
27
|
+
e_none_socket = -> {
|
28
|
+
begin; fail 'Timeout without correct token'; rescue errors_with_message(/socket/); end
|
29
|
+
}
|
30
|
+
expect(&e_none_socket).to raise_exception(RuntimeError, 'Timeout without correct token')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe NestedException do
|
35
|
+
specify 'wraps $! exception' do
|
36
|
+
begin
|
37
|
+
fail 'OriginalException'
|
38
|
+
rescue => e_original
|
39
|
+
begin
|
40
|
+
raise NestedException, e_original.message + '::NestingException'
|
41
|
+
rescue => e_nesting
|
42
|
+
e_nesting.should respond_to :original
|
43
|
+
e_nesting.original.should be e_original
|
44
|
+
e_nesting.message.should == 'OriginalException::NestingException'
|
45
|
+
e_nesting.original.message.should == 'OriginalException'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Rubymisc::Float do
|
6
|
+
describe '#percent_of' do
|
7
|
+
specify '50.0 is 50.0 percent of 100' do
|
8
|
+
(50.0).percent_of(100).should be_kind_of Float
|
9
|
+
(50.0).percent_of(100).should == 50.0
|
10
|
+
end
|
11
|
+
|
12
|
+
specify '0.0 is 0.0 percent of 100' do
|
13
|
+
(0.0).percent_of(100).should be_kind_of Float
|
14
|
+
(0.0).percent_of(100).should == 0.0
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Rubymisc::Integer do
|
6
|
+
describe '#percent_of' do
|
7
|
+
specify '50 is 50.0 percent of 100' do
|
8
|
+
50.percent_of(100).should be_kind_of Float
|
9
|
+
50.percent_of(100).should == 50.0
|
10
|
+
end
|
11
|
+
|
12
|
+
specify '0 is 0.0 percent of 100' do
|
13
|
+
0.percent_of(100).should be_kind_of Float
|
14
|
+
0.percent_of(100).should == 0.0
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Rubymisc::Object do
|
6
|
+
let(:collection) { [1, 2, 3, 4, 5, 100] }
|
7
|
+
|
8
|
+
describe '#in?' do
|
9
|
+
context 'given collection includes element' do
|
10
|
+
specify 'returns true' do
|
11
|
+
100.in?(collection).should be_true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'given collection does not include element' do
|
16
|
+
specify 'returns false' do
|
17
|
+
101.in?(collection).should be_false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#not Functor' do
|
23
|
+
specify 'String#empty? returns false for blank string with #not Functor' do
|
24
|
+
''.empty?.should be true
|
25
|
+
''.not.empty?.should be false
|
26
|
+
end
|
27
|
+
|
28
|
+
specify 'Object#instance_of? returns false when class matches with #not Functor' do
|
29
|
+
100.instance_of?(Fixnum).should be true
|
30
|
+
100.not.instance_of?(Fixnum).should be false
|
31
|
+
end
|
32
|
+
|
33
|
+
specify 'Enumerable#include? returns false for collection having an element with #not Functor' do
|
34
|
+
collection.include?(1).should be true
|
35
|
+
collection.not.include?(1).should be false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe 'Rubymisc::Regex::Manual' do
|
6
|
+
specify '.man' do
|
7
|
+
Rubymisc::Regex.man.should be_start_with <<-EOS
|
8
|
+
Ruby character representations
|
9
|
+
------------------------------
|
10
|
+
Sequence Meaning
|
11
|
+
\\a Alert (bell), \\x07.
|
12
|
+
\\b Backspace, \\x08, supported only in character class.
|
13
|
+
\\e ESC character, \\x1B.
|
14
|
+
\\n Newline, \\x0A.
|
15
|
+
\\r Carriage return, \\x0D.
|
16
|
+
\\f Form feed, \\x0C.
|
17
|
+
\\t Horizontal tab \\x09.
|
18
|
+
\\v Vertical tab, \\x0B.
|
19
|
+
\\0octal Character specified by a two-digit octal code.
|
20
|
+
\\xhex Character specified by a two-digit hexadecimal code.
|
21
|
+
\\cchar Named control character.
|
22
|
+
EOS
|
23
|
+
|
24
|
+
puts "\n" + Rubymisc::Regex.man
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Rubymisc::Regex do
|
6
|
+
describe '.email' do
|
7
|
+
specify 'valid email regexp' do
|
8
|
+
Rubymisc::Regex.email.should match 'ipoval@ya.ru'
|
9
|
+
Rubymisc::Regex.email.should match 'ivan-poval@yandex.ru'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '.url' do
|
14
|
+
specify 'valid url regexp' do
|
15
|
+
Rubymisc::Regex.url.should match 'http://google.com'
|
16
|
+
Rubymisc::Regex.url.should match 'http://www.google.com'
|
17
|
+
Rubymisc::Regex.url.should match 'https://google.com'
|
18
|
+
Rubymisc::Regex.url.should match 'https://www.google.com'
|
19
|
+
Rubymisc::Regex.url.should match 'http://google.com/'
|
20
|
+
Rubymisc::Regex.url.should match 'http://www.google.com/'
|
21
|
+
Rubymisc::Regex.url.should match 'https://google.com/'
|
22
|
+
Rubymisc::Regex.url.should match 'https://www.google.com/'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '.zip' do
|
27
|
+
specify 'valid zip regexp' do
|
28
|
+
Rubymisc::Regex.zip.should match '90028'
|
29
|
+
Rubymisc::Regex.zip.should match '90028-0000'
|
30
|
+
Rubymisc::Regex.zip.should_not match '9002'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '.ipv4' do
|
35
|
+
specify 'valid dotted quad IP address' do
|
36
|
+
Rubymisc::Regex.ipv4.should match '127.0.0.1'
|
37
|
+
Rubymisc::Regex.ipv4.should match '224.22.5.110'
|
38
|
+
Rubymisc::Regex.ipv4.should_not match '127.1'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '.mac_address' do
|
43
|
+
specify 'valid mac address' do
|
44
|
+
Rubymisc::Regex.mac_address.should match '01:23:45:67:89:ab'
|
45
|
+
Rubymisc::Regex.mac_address.should_not match '01:23:45'
|
46
|
+
Rubymisc::Regex.mac_address.should_not match '0123456789ab'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '.hexcode' do
|
51
|
+
specify 'valid html hex code' do
|
52
|
+
Rubymisc::Regex.hexcode.should match '#aaa'
|
53
|
+
Rubymisc::Regex.hexcode.should match '#000000'
|
54
|
+
Rubymisc::Regex.hexcode.should_not match 'fff'
|
55
|
+
Rubymisc::Regex.hexcode.should_not match '#ggg'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '.usd' do
|
60
|
+
specify '.usd' do
|
61
|
+
Rubymisc::Regex.usd.should match '$20'
|
62
|
+
Rubymisc::Regex.usd.should match '$15,000.01'
|
63
|
+
Rubymisc::Regex.usd.should_not match '$1.001'
|
64
|
+
Rubymisc::Regex.usd.should_not match '$.99'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/spec/spec.rake
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
|
5
|
+
desc 'Run complete application spec suite'
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
|
8
|
+
spec_tasks = Dir['spec/*/'].map { |d| File.basename(d) }
|
9
|
+
|
10
|
+
spec_tasks.each do |folder|
|
11
|
+
RSpec::Core::RakeTask.new("spec:#{folder}") do |t|
|
12
|
+
t.pattern = "./spec/#{folder}/**/*_spec.rb"
|
13
|
+
t.rspec_opts = %w(--color)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# task 'spec' => spec_tasks.map { |f| "spec:#{f}" }
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
$:.unshift File.expand_path('../lib', __FILE__)
|
4
|
+
|
5
|
+
# Use simplecov test coverage
|
6
|
+
require 'simplecov'
|
7
|
+
SimpleCov.start
|
8
|
+
|
9
|
+
require 'rubymisc'
|
10
|
+
Dir['./spec/support/**/*.rb'].each { |f| require f }
|
11
|
+
|
12
|
+
RSpec.configure do |conf|
|
13
|
+
conf.color_enabled = true
|
14
|
+
conf.treat_symbols_as_metadata_keys_with_true_values = true
|
15
|
+
|
16
|
+
conf.expect_with :rspec, :stdlib
|
17
|
+
conf.mock_with :rspec
|
18
|
+
|
19
|
+
conf.fail_fast = true
|
20
|
+
conf.filter_run :focus => true
|
21
|
+
conf.filter_run_excluding :broken => true
|
22
|
+
conf.run_all_when_everything_filtered = true
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubymisc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ivan Povalyukhin
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-12-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: :rspec
|
16
|
+
requirement: &2152338320 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.8.0.rc1
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2152338320
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: :rake
|
27
|
+
requirement: &2152337660 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.9.2
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2152337660
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: :bundler
|
38
|
+
requirement: &2152337020 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.0.21
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2152337020
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: :simplecov
|
49
|
+
requirement: &2152332880 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.5.4
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2152332880
|
58
|
+
description: Miscellaneous and humble tool-set of useful Ruby.
|
59
|
+
email:
|
60
|
+
- ipoval@ya.ru
|
61
|
+
executables: []
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files: []
|
64
|
+
files:
|
65
|
+
- .gitignore
|
66
|
+
- .rvmrc
|
67
|
+
- Gemfile
|
68
|
+
- README
|
69
|
+
- Rakefile
|
70
|
+
- lib/rubymisc.rb
|
71
|
+
- lib/rubymisc/exceptional.rb
|
72
|
+
- lib/rubymisc/ext/active_record.rb
|
73
|
+
- lib/rubymisc/ext/float.rb
|
74
|
+
- lib/rubymisc/ext/integer.rb
|
75
|
+
- lib/rubymisc/ext/object.rb
|
76
|
+
- lib/rubymisc/regex.rb
|
77
|
+
- lib/rubymisc/regex/manual.rb
|
78
|
+
- lib/rubymisc/version.rb
|
79
|
+
- rubymisc.gemspec
|
80
|
+
- spec/rubymisc/exceptional_spec.rb
|
81
|
+
- spec/rubymisc/ext/float_spec.rb
|
82
|
+
- spec/rubymisc/ext/integer_spec.rb
|
83
|
+
- spec/rubymisc/ext/object_spec.rb
|
84
|
+
- spec/rubymisc/regex/manual_spec.rb
|
85
|
+
- spec/rubymisc/regex_spec.rb
|
86
|
+
- spec/rubymisc/version_spec.rb
|
87
|
+
- spec/rubymisc_spec.rb
|
88
|
+
- spec/spec.rake
|
89
|
+
- spec/spec_helper.rb
|
90
|
+
homepage: https://github.com/ipoval/rubymisc
|
91
|
+
licenses: []
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 1.9.3
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ! '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: 1.3.5
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project: rubymisc
|
110
|
+
rubygems_version: 1.8.10
|
111
|
+
signing_key:
|
112
|
+
specification_version: 3
|
113
|
+
summary: Ruby miscellaneous.
|
114
|
+
test_files:
|
115
|
+
- spec/rubymisc/exceptional_spec.rb
|
116
|
+
- spec/rubymisc/ext/float_spec.rb
|
117
|
+
- spec/rubymisc/ext/integer_spec.rb
|
118
|
+
- spec/rubymisc/ext/object_spec.rb
|
119
|
+
- spec/rubymisc/regex/manual_spec.rb
|
120
|
+
- spec/rubymisc/regex_spec.rb
|
121
|
+
- spec/rubymisc/version_spec.rb
|
122
|
+
- spec/rubymisc_spec.rb
|
123
|
+
- spec/spec.rake
|
124
|
+
- spec/spec_helper.rb
|