divisible 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  pkg/*
2
- *.gem
2
+ *.gem
3
+ Gemfile.lock
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source :gemcutter
1
+ source :rubygems
2
2
 
3
3
  # Specify your gem's dependencies in divisible.gemspec
4
4
  gemspec
@@ -1,14 +1,24 @@
1
1
  = Divisible
2
2
 
3
- Divisible is a Ruby gem useful in case you need to find out if one number is divisible by another
3
+ Still using the C way of testing if one number is divisible by another?
4
+
5
+ Still using this?
6
+
7
+ x % 13 == 0 || x % 6 == 0 || x % 3 == 0
8
+
9
+ No need anymore! We present you *Divisible*. Check if number is divisible by another like a boss!
10
+
11
+ x.divisible_by? 13, 6, 3
4
12
 
5
13
  == Examples
6
14
 
7
- 9.divisible_by(3) # => true
8
- 10.divisible_by(3) # => false
9
- 12.divisible_by(3) # => true
10
- 12.divisible_by(4) # => true
11
- 15.divisible_by(4) # => false
15
+ 9.divisible_by? 3 # => true
16
+ 10.divisible_by? 3 # => false
17
+ 12.divisible_by? 3 # => true
18
+ 12.divisible_by? 4 # => true
19
+ 15.divisible_by? 4 # => false
20
+ 21.divisible_by? 3,7 # => true
21
+ 35.divisible_by? 3,5,0 # => false
12
22
 
13
23
  Same can be done with
14
24
 
data/Rakefile CHANGED
@@ -1,2 +1,11 @@
1
1
  require 'bundler'
2
- Bundler::GemHelper.install_tasks
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << 'test'
8
+ end
9
+
10
+ desc "Run tests"
11
+ task :default => :test
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
2
+ $:.push File.expand_path("../lib", __FILE__)
3
3
  require 'divisible/version'
4
4
 
5
5
  Gem::Specification.new do |s|
@@ -14,10 +14,11 @@ Gem::Specification.new do |s|
14
14
 
15
15
  s.required_rubygems_version = ">= 1.3.6"
16
16
  s.rubyforge_project = "divisible"
17
-
18
- s.add_development_dependency "bundler", ">= 1.0.0.rc.5"
17
+
18
+ s.add_development_dependency "rake"
19
19
 
20
20
  s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
22
  s.executables = `git ls-files`.split("\n").select{|f| f =~ /^bin/}
22
23
  s.require_path = 'lib'
23
24
  end
@@ -1,13 +1,9 @@
1
1
  require "divisible/core_ext"
2
2
 
3
3
  module Divisible
4
-
5
4
  class << self
6
-
7
5
  def check(n, d)
8
6
  n % d == 0
9
7
  end
10
-
11
8
  end
12
-
13
- end
9
+ end
@@ -1,7 +1,15 @@
1
1
  class Fixnum
2
-
3
- def divisible_by(d)
4
- Divisible.check(self, d)
2
+ def divisible_by?(first,*args)
3
+ args += [first]
4
+ args.each do |arg|
5
+ return false unless Divisible.check(self, arg)
6
+ end
7
+ true
5
8
  end
6
9
 
7
- end
10
+ # <b>DEPRECATED:</b> Please use <tt>divisible_by?</tt> instead.
11
+ def divisible_by(*args)
12
+ warn "[DEPRECATION] `divisible_by` is deprecated. Please use `divisible_by?` instead."
13
+ divisible_by?(*args)
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module Divisible
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -0,0 +1,50 @@
1
+ require "test/unit"
2
+ require "divisible"
3
+ require "divisible/core_ext"
4
+
5
+
6
+ class TestDivisible < Test::Unit::TestCase
7
+ def test_if_loaded
8
+ assert Fixnum.method_defined?(:divisible_by?)
9
+ end
10
+
11
+ def check_module_call
12
+ assert Divisible.check(4,2)
13
+ end
14
+
15
+ def test_simple
16
+ assert 2.divisible_by?(2)
17
+ assert !4.divisible_by?(3)
18
+ end
19
+
20
+ def test_complex
21
+ assert 100.divisible_by?(2,4,5,10,20,25,50)
22
+ assert !100.divisible_by?(2,3)
23
+ end
24
+
25
+ def test_complex_with_zero
26
+ assert_raise ZeroDivisionError do
27
+ assert_equal false, 100.divisible_by?(2,4,5,10,20,25,50,0)
28
+ end
29
+ end
30
+
31
+ def test_blank
32
+ assert_raise ArgumentError do
33
+ 2.divisible_by?
34
+ end
35
+ end
36
+
37
+ def test_division_by_zero
38
+ assert_raise ZeroDivisionError do
39
+ assert_equal false, 2.divisible_by?(0)
40
+ end
41
+ end
42
+
43
+ def test_that_divisible_by_still_works_as_deprecated_method
44
+ assert Fixnum.method_defined?(:divisible_by)
45
+ assert_equal 4.divisible_by(2), 4.divisible_by?(2)
46
+ assert_equal 4.divisible_by(3), 4.divisible_by?(3)
47
+ assert_equal 100.divisible_by(2,4,5,10,20,25,50), 100.divisible_by?(2,4,5,10,20,25,50)
48
+ end
49
+
50
+ end
metadata CHANGED
@@ -2,12 +2,12 @@
2
2
  name: divisible
3
3
  version: !ruby/object:Gem::Version
4
4
  hash: 27
5
- prerelease: false
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 2
10
- version: 0.0.2
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Vlado Cingel
@@ -15,27 +15,22 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-26 00:00:00 +01:00
19
- default_executable:
18
+ date: 2012-02-27 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
- name: bundler
23
21
  prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
22
+ name: rake
23
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
24
  none: false
26
25
  requirements:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
- hash: 15424063
28
+ hash: 3
30
29
  segments:
31
- - 1
32
- - 0
33
30
  - 0
34
- - rc
35
- - 5
36
- version: 1.0.0.rc.5
31
+ version: "0"
37
32
  type: :development
38
- version_requirements: *id001
33
+ requirement: *id001
39
34
  description: Useful to find out if one number is divisible by another. For example 9.divisible_by(3) will return true, and 10.divisible_by(3) will return false
40
35
  email:
41
36
  - vlado@cingel.hr
@@ -54,7 +49,7 @@ files:
54
49
  - lib/divisible.rb
55
50
  - lib/divisible/core_ext.rb
56
51
  - lib/divisible/version.rb
57
- has_rdoc: true
52
+ - test/test_divisible.rb
58
53
  homepage: https://github.com/vlado/divisible
59
54
  licenses: []
60
55
 
@@ -86,9 +81,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
81
  requirements: []
87
82
 
88
83
  rubyforge_project: divisible
89
- rubygems_version: 1.3.7
84
+ rubygems_version: 1.8.12
90
85
  signing_key:
91
86
  specification_version: 3
92
87
  summary: Useful to find out if one number is divisible by another
93
- test_files: []
94
-
88
+ test_files:
89
+ - test/test_divisible.rb