guerrilla_patch 2.8.2 → 2.8.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - jruby-19mode # JRuby in 1.9 mode
5
+ - rbx-19mode
data/Gemfile CHANGED
@@ -1,6 +1,7 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  gemspec
4
+ gem 'rake'
4
5
 
5
6
  group :development, :test do
6
7
  gem "rspec", "~> 2.8.0"
@@ -1,12 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- guerrilla_patch (2.8.2)
4
+ guerrilla_patch (2.8.3)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
8
8
  specs:
9
9
  diff-lcs (1.1.3)
10
+ rake (0.9.2.2)
10
11
  rspec (2.8.0)
11
12
  rspec-core (~> 2.8.0)
12
13
  rspec-expectations (~> 2.8.0)
@@ -22,4 +23,5 @@ PLATFORMS
22
23
  DEPENDENCIES
23
24
  bundler (>= 1.0.0)
24
25
  guerrilla_patch!
26
+ rake
25
27
  rspec (~> 2.8.0)
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  Guerrilla Patch
2
2
  ================
3
+ [![Build Status](https://travis-ci.org/drKreso/guerrilla_patch.png)](https://travis-ci.org/drKreso/guerrilla_patch)
4
+
3
5
 
4
6
  I am tired of hunting and tracking down my own monkey patches. Not to mention hassle of dragging them between projects. I figured gem is a remedy for this.
5
7
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.8.1
1
+ 2.8.2
@@ -9,14 +9,15 @@ class Allocate
9
9
 
10
10
  def divided
11
11
  divided_ratios = @ratios.map { |ratio| ratio.to_d/ratios.sum_me.to_d }
12
- compensate_last_slice( divided_ratios.map { |ratio| (@amount * ratio).round(2) } )
12
+ rates = divided_ratios.map { |ratio| ((@amount * ratio).round(2)) }
13
+ compensate_last_slice(rates)
13
14
  end
14
-
15
+
15
16
  def compensate_last_slice(rates)
16
17
  rates.tap do |rates|
17
- rates[-1] = rates[-1] + (amount - rates.sum_me).round(2)
18
- if ( amount > 0 && ( rates.select {|item| item <= 0 }.count > 0 ) ) ||
19
- ( amount < 0 && ( rates.select {|item| item >= 0 }.count > 0 ) )
18
+ max_rate = rates.max.abs
19
+ rates[-1] = (rates[-1] + (amount - rates.sum_me)).round(2)
20
+ if rates[-1].abs > (2 * max_rate.abs )
20
21
  raise "Number is too small to be allocated on that number of slices(#@amount on #{@ratios.size} slices)."
21
22
  end
22
23
  end
@@ -62,6 +62,10 @@ class Float
62
62
  def divide(ratios)
63
63
  DivideByType.divide(ratios, self)
64
64
  end
65
+
66
+ def negative
67
+ -self
68
+ end
65
69
  end
66
70
 
67
71
  class BigDecimal
@@ -81,6 +85,12 @@ class Fixnum
81
85
 
82
86
  end
83
87
 
88
+ class BigDecimal
89
+ def negative
90
+ -self
91
+ end
92
+ end
93
+
84
94
  class Hash
85
95
  def sum_me
86
96
  self.each_value.reduce(0,:+)
@@ -1,3 +1,3 @@
1
1
  module GuerrillaPatch
2
- VERSION = "2.8.2"
2
+ VERSION = "2.8.3"
3
3
  end
@@ -22,5 +22,9 @@ describe DivideByType do
22
22
  it 'knows how to divide without ratios' do
23
23
  DivideByType.divide({}, 10).should == { :no_division => 10}
24
24
  end
25
+
26
+ it 'knows how to divide negative ratios' do
27
+ DivideByType.divide({"E2112"=>279.37, "E2111"=>-233.06}, 46.31).should == { "E2112" => 279.37, "E2111" => -233.06 }
28
+ end
25
29
  end
26
30
 
@@ -48,13 +48,13 @@ describe Allocate do
48
48
 
49
49
  it 'should raise exception for number that is too small' do
50
50
  lambda do
51
- Allocate.evenly(0.1,20)
51
+ Allocate.evenly(0.1, 20)
52
52
  end.should raise_error 'Number is too small to be allocated on that number of slices(0.1 on 20 slices).'
53
53
  end
54
54
 
55
55
  it 'should raise exception for number that is too small negative' do
56
56
  lambda do
57
- Allocate.evenly(-0.1,20)
57
+ Allocate.evenly(-0.1, 20)
58
58
  end.should raise_error 'Number is too small to be allocated on that number of slices(-0.1 on 20 slices).'
59
59
  end
60
60
 
@@ -64,4 +64,4 @@ describe Allocate do
64
64
  subject.divided.inject(0) { | sum, item | sum += item }.should == subject.amount
65
65
  end
66
66
 
67
- end
67
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guerrilla_patch
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.2
4
+ version: 2.8.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -21,6 +21,7 @@ files:
21
21
  - .document
22
22
  - .gitignore
23
23
  - .rspec
24
+ - .travis.yml
24
25
  - Gemfile
25
26
  - Gemfile.lock
26
27
  - LICENSE.txt
@@ -55,12 +56,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
55
56
  - - ! '>='
56
57
  - !ruby/object:Gem::Version
57
58
  version: '0'
59
+ segments:
60
+ - 0
61
+ hash: 692317867878337078
58
62
  required_rubygems_version: !ruby/object:Gem::Requirement
59
63
  none: false
60
64
  requirements:
61
65
  - - ! '>='
62
66
  - !ruby/object:Gem::Version
63
67
  version: '0'
68
+ segments:
69
+ - 0
70
+ hash: 692317867878337078
64
71
  requirements: []
65
72
  rubyforge_project:
66
73
  rubygems_version: 1.8.24