rubymisc 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc CHANGED
@@ -1 +1 @@
1
- rvm use 1.9.3@rubymisc 2>/dev/null
1
+ rvm use 1.9.3
data/Gemfile CHANGED
@@ -1,2 +1,2 @@
1
- source :rubygems
1
+ source 'http://rubygems.org'
2
2
  gemspec
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011 @ipoval (Ivan Povalyukhin)
1
+ Copyright (c) 2013 @ipoval (Ivan Povalyukhin)
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README CHANGED
@@ -37,18 +37,15 @@
37
37
  p 'socket E'
38
38
  end
39
39
 
40
- #ASSERT
41
- e13: ASSERT { fail SecurityError.new('Fail message!') }
42
-
43
40
  2.3 Integer
44
41
 
45
42
  #percent_of
46
- e14: 50.percent_of(100) # => 50.0
43
+ e13: 50.percent_of(100) # => 50.0
47
44
 
48
45
  2.4 String
49
46
 
50
47
  #^, #xor
51
- e15: 'rubymisc'.xor 'test' # => "\u0006\u0010\u0011\r\u0019\f\u0000\u0017"
48
+ e14: 'rubymisc'.xor 'test' # => "\u0006\u0010\u0011\r\u0019\f\u0000\u0017"
52
49
 
53
50
  2.5 ActiveRecord::Base
54
51
 
data/lib/rubymisc.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  # This module encapsulates the entry point functionality to
4
4
  # the extension modules.
5
5
  #--
6
- # Copyright (c) 2011 Ivan Povalyukhin.
6
+ # Copyright (c) 2013 Ivan Povalyukhin.
7
7
  # Licensed under the same terms as Ruby. No warranty is provided.
8
8
  module Rubymisc
9
9
  class << self
@@ -2,26 +2,18 @@
2
2
 
3
3
  module Rubymisc
4
4
  module Exceptional
5
- def ASSERT(&block)
6
- begin
7
- yield
8
- rescue Exception => e
9
- STDERR.puts e.inspect
10
- STDERR.puts e.backtrace
11
- # raise e.class, "#{e.message}", caller
12
- end
13
- end
14
-
15
5
  ##
16
6
  # @example
17
- # begin; raise 'Timeout socket'; rescue errors_with_message(/socket/); p 'socket E'; end
7
+ # begin
8
+ # raise 'Timeout socket'
9
+ # rescue errors_with_message /socket/
10
+ # p 'socket E'
11
+ # end
18
12
  #
19
13
  def errors_with_message(pattern)
20
14
  m = Module.new
21
15
  (class << m; self; end).instance_eval do
22
- define_method(:===) do |e|
23
- pattern === e.message
24
- end
16
+ define_method(:===) { |e| pattern === e.message }
25
17
  end
26
18
  m
27
19
  end
@@ -12,6 +12,25 @@ module Rubymisc
12
12
  /\A#{email_name_regex}@#{domain_head_regex}#{domain_tld_regex}\z/i
13
13
  end
14
14
 
15
+ def phone
16
+ /\A
17
+ (?:
18
+ (?<prefix>\d) # prefix digit
19
+ [ \-\.]? # optional separator
20
+ )?
21
+ (?:
22
+ \(?(?<areacode>\d{3})\)? # area code
23
+ [ \-\.] # separator
24
+ )?
25
+ (?<trunk>\d{3}) # trunk
26
+ [ \-\.] # separator
27
+ (?<line>\d{4}) # line
28
+ (?:\ ?x? # optional space or 'x'
29
+ (?<extension>\d+) # extension
30
+ )?
31
+ \z/x
32
+ end
33
+
15
34
  def url
16
35
  /\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
36
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Rubymisc
4
- VERSION = '0.0.4'
4
+ VERSION = '0.1.0'
5
5
  end
data/rubymisc.gemspec CHANGED
@@ -20,14 +20,14 @@ Gem::Specification.new do |s|
20
20
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
21
  s.require_paths = ['lib']
22
22
 
23
- s.required_ruby_version = '>= 1.9.2'
23
+ s.required_ruby_version = '>= 1.9.3'
24
24
  s.required_rubygems_version = '>= 1.3.5'
25
25
 
26
26
  s.extra_rdoc_files = ['README']
27
27
  s.license = 'MIT'
28
28
 
29
- { rspec: '~> 2.8.0',
29
+ { rspec: '~> 2.11.0',
30
30
  rake: '~> 0.9.2.2',
31
- bundler: '~> 1.0.21',
32
- simplecov: '~> 0.5.4' }.each { |lib, v| s.add_development_dependency lib.to_s, v }
31
+ bundler: '~> 1.3.4',
32
+ simplecov: '~> 0.6.1' }.each { |lib, v| s.add_development_dependency lib.to_s, v }
33
33
  end
@@ -3,18 +3,6 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe Rbm::Exceptional do
6
- describe '#ASSERT' do
7
- specify 'catches failing block and swallows the exception' do
8
- failing_proc = -> { fail SecurityError.new('Fail message!') }
9
- expect { ASSERT &failing_proc }.not_to raise_error
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
6
  describe '#errors_with_message' do
19
7
  specify 'rescue an exception if message match' do
20
8
  e_socket = -> {
@@ -64,4 +64,12 @@ describe Rbm::Regex do
64
64
  Rbm::Regex.usd.should_not match '$.99'
65
65
  end
66
66
  end
67
+
68
+ describe '.phone' do
69
+ specify 'valid phone number' do
70
+ Rbm::Regex.phone.should match '310-293-5555'
71
+ Rbm::Regex.phone.should match '(310)-293-5555'
72
+ Rbm::Regex.phone.should match '310.293.5555'
73
+ end
74
+ end
67
75
  end
data/spec/spec_helper.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  $:.unshift File.expand_path('../lib', __FILE__)
4
4
 
5
- require 'simplecov' # use simplecov test coverage
5
+ require 'simplecov'
6
6
  SimpleCov.start
7
7
 
8
8
  require 'yaml'
@@ -12,6 +12,7 @@ require 'rubymisc'
12
12
  Dir['./spec/support/**/*.rb'].each { |f| require f }
13
13
 
14
14
  RSpec.configure do |conf|
15
+ conf.order = 'random'
15
16
  conf.color_enabled = true
16
17
  conf.treat_symbols_as_metadata_keys_with_true_values = true
17
18
 
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.4
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-28 00:00:00.000000000 Z
12
+ date: 2013-04-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &2152648740 !ruby/object:Gem::Requirement
16
+ requirement: &2160298400 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 2.8.0
21
+ version: 2.11.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2152648740
24
+ version_requirements: *2160298400
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &2152648280 !ruby/object:Gem::Requirement
27
+ requirement: &2160349140 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,29 +32,29 @@ dependencies:
32
32
  version: 0.9.2.2
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2152648280
35
+ version_requirements: *2160349140
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &2152647820 !ruby/object:Gem::Requirement
38
+ requirement: &2160348480 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
42
42
  - !ruby/object:Gem::Version
43
- version: 1.0.21
43
+ version: 1.3.4
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2152647820
46
+ version_requirements: *2160348480
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: simplecov
49
- requirement: &2152647360 !ruby/object:Gem::Requirement
49
+ requirement: &2160347800 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: 0.5.4
54
+ version: 0.6.1
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2152647360
57
+ version_requirements: *2160347800
58
58
  description: Miscellaneous and humble tool-set of useful Ruby.
59
59
  email:
60
60
  - ipoval@ya.ru
@@ -106,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
106
  requirements:
107
107
  - - ! '>='
108
108
  - !ruby/object:Gem::Version
109
- version: 1.9.2
109
+ version: 1.9.3
110
110
  required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  none: false
112
112
  requirements:
@@ -115,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  version: 1.3.5
116
116
  requirements: []
117
117
  rubyforge_project: rubymisc
118
- rubygems_version: 1.8.10
118
+ rubygems_version: 1.8.17
119
119
  signing_key:
120
120
  specification_version: 3
121
121
  summary: Ruby miscellaneous.