finishing_moves 0.4.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ddfa53a9f4220a6334ab8949533d87d4a63e52f4
4
- data.tar.gz: fac82ddd74402c7e607dc8a53cf83141df008ae3
3
+ metadata.gz: dcac065bb1179f4a20504dfa28a865c8dabd537d
4
+ data.tar.gz: 69dcdfb5bc2d249cc69cf59feb5ea8abd02ee22a
5
5
  SHA512:
6
- metadata.gz: ccae2fc1ca05fc5f4d25fe46fbd0b642b69a78fe47fdafbc69f0ba4180b9b86599bfc3db11bed729e4c1649ee41c834f2e2fa4f5041aeb6850d7ac85e87090a4
7
- data.tar.gz: d35ce701e2729cd3ed48c2c93399bfd035db523b3ffb5d199f8c2ae9994a7b63beb98553a373216f29dc07a62bda91e35d0015cec9572abad6bfbe5bbe9ac976
6
+ metadata.gz: 94dc40dac77c92b1d1f046c309d3c04e7a7e50a3b7bd173906ad39be08d4a39b68e501a53d34d2a097ef79c5157753f61b05a71c06009c48e36a199c5ff10c64
7
+ data.tar.gz: 6886af0eda4b7aa7cb864d740744518be9f50930b9b775e871397ee678f120a1b4bbd8469c51ebaf07280652b0ce97452560149fded283be37e46f054775cd6a
data/README.md CHANGED
@@ -36,10 +36,12 @@ Tested against **`2.0.0` and above**. Probably works in `1.9.3`.
36
36
  - [`Hash#delete!`](https://github.com/forgecrafted/finishing_moves/wiki/Hash#hashdelete)
37
37
  - [`Hash#delete_each`](https://github.com/forgecrafted/finishing_moves/wiki/Hash#hashdelete_each)
38
38
  - [`Hash#delete_each!`](https://github.com/forgecrafted/finishing_moves/wiki/Hash#hashdelete_each-1)
39
- - [`Integer#length`](https://github.com/forgecrafted/finishing_moves/wiki/Integer#integerlength)
39
+ - [`Integer#length`](https://github.com/forgecrafted/finishing_moves/wiki/Numeric#integerlength)
40
40
  - [`Kernel#nil_chain`](https://github.com/forgecrafted/finishing_moves/wiki/Kernel#kernelnil_chain) :boom:
41
41
  - [`Kernel#cascade`](https://github.com/forgecrafted/finishing_moves/wiki/Kernel#kernelcascade)
42
42
  - [`Kernel#class_exists?`](https://github.com/forgecrafted/finishing_moves/wiki/Kernel#kernelclass_exists)
43
+ - [`Numeric#add_percent`](https://github.com/forgecrafted/finishing_moves/wiki/Numeric#numericadd_percent)
44
+ - [`Numeric#subtract_percent`](https://github.com/forgecrafted/finishing_moves/wiki/Numeric#numericsubtract_percent)
43
45
  - [`Object#same_as`](https://github.com/forgecrafted/finishing_moves/wiki/Object#objectsame_as)
44
46
  - [`Object#not_nil?`](https://github.com/forgecrafted/finishing_moves/wiki/Object#objectnot_nil)
45
47
  - [`Object#is_an?`](https://github.com/forgecrafted/finishing_moves/wiki/Object#objectis_an)
data/Rakefile CHANGED
@@ -1,15 +1,24 @@
1
+
1
2
  desc "Open an irb session preloaded with this library"
2
3
  task :console do
3
4
  sh "irb -rubygems -I lib -r finishing_moves.rb"
4
5
  end
5
6
  task :c => :console
6
7
 
7
- desc "Connect to RubyGems.org account"
8
- task :authgem do
9
- sh "curl -u forgecrafted https://rubygems.org/api/v1/api_key.yaml > ~/.gem/credentials; chmod 0600 ~/.gem/credentials"
10
- end
8
+ namespace :gem do
9
+ desc "Connect to RubyGems.org account"
10
+ task :auth do
11
+ sh "curl -u forgecrafted https://rubygems.org/api/v1/api_key.yaml > ~/.gem/credentials; chmod 0600 ~/.gem/credentials"
12
+ end
13
+
14
+ desc "Build the gem according to gemspec"
15
+ task :build do
16
+ sh "gem build finishing_moves.gemspec"
17
+ end
11
18
 
12
- desc "Build the gem according to gemspec"
13
- task :buildgem do
14
- sh "gem build finishing_moves.gemspec"
19
+ require "./lib/finishing_moves/version"
20
+ desc "Push the gem to RubyGems.org"
21
+ task :push do
22
+ sh "gem push finishing_moves-#{FinishingMoves::VERSION}.gem"
23
+ end
15
24
  end
@@ -0,0 +1,23 @@
1
+ class Numeric
2
+ def length
3
+ raise ArgumentError.new("Cannot get length: \"#{self}\" is not an integer")
4
+ end
5
+ alias_method :digits, :length
6
+
7
+ def subtract_percent(percent)
8
+ self.to_f * ( ( 100.0 - percent.to_f ) / 100.0 )
9
+ end
10
+ alias_method :percentage_off, :subtract_percent
11
+
12
+ def add_percent(percent)
13
+ self.to_f + ( self.to_f * ( percent.to_f / 100.0 ) )
14
+ end
15
+ alias_method :markup_by_percent, :add_percent
16
+ end
17
+
18
+ class Integer
19
+ def length
20
+ Math.log10(self.abs).to_i + 1
21
+ end
22
+ alias_method :digits, :length
23
+ end
@@ -1,3 +1,3 @@
1
1
  module FinishingMoves
2
- VERSION = "0.4.1"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -0,0 +1,101 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Numeric methods" do
4
+
5
+ it "Fixnum#length" do
6
+ expect(1.length).to eq 1
7
+ expect(5.length).to eq 1
8
+ expect(9.length).to eq 1
9
+ expect(90.length).to eq 2
10
+ expect(900.length).to eq 3
11
+ expect(9000.length).to eq 4
12
+ expect(-9000.length).to eq 4
13
+ # alias
14
+ expect(-9000.digits).to eq 4
15
+ end
16
+
17
+ it "Bignum#length" do
18
+ expect(12356469787881584554556.length).to eq 23
19
+ expect(-12356469787881584554556.length).to eq 23
20
+ # alias
21
+ expect(-12356469787881584554556.digits).to eq 23
22
+ end
23
+
24
+ it "Float#length" do
25
+ expect{ 0.0.length }.to raise_error(ArgumentError)
26
+ expect{ 1.0.length }.to raise_error(ArgumentError)
27
+ expect{ -1.0.length }.to raise_error(ArgumentError)
28
+ expect{ 3.14.length }.to raise_error(ArgumentError)
29
+ expect{ 12356469.987.length }.to raise_error(ArgumentError)
30
+ # alias
31
+ expect{ 12356469.987.digits }.to raise_error(ArgumentError)
32
+ end
33
+
34
+ it "BigDecimal#length" do
35
+ expect{ 1265437718438866624512.123.length }.to raise_error(ArgumentError)
36
+ expect{ -1265437718438866624512.123.length }.to raise_error(ArgumentError)
37
+ expect{ 0.9999999999999062.length }.to raise_error(ArgumentError)
38
+ expect{ -0.9999999999999062.length }.to raise_error(ArgumentError)
39
+ # alias
40
+ expect{ -0.9999999999999062.digits }.to raise_error(ArgumentError)
41
+ end
42
+
43
+ it "Fixnum#subtract_percent" do
44
+ expect(1.subtract_percent(10)).to eq 0.9
45
+ expect(10.subtract_percent(10)).to eq 9.0
46
+ expect(25.subtract_percent(5)).to eq 23.75
47
+ expect(76.subtract_percent(40)).to eq 45.6
48
+ expect(76.percentage_off(40)).to eq 45.6
49
+ expect(98786.percentage_off(100)).to eq 0
50
+ end
51
+
52
+ it "Bignum#subtract_percent" do
53
+ expect(12356469787881584554556.subtract_percent(10)).to eq 1.1120822809093428e+22
54
+ expect(12356469787881584554556.subtract_percent(99)).to eq 1.2356469787881585e+20
55
+ expect(12356469787881584554556.percentage_off(99.99999)).to eq 1235646979180369.8
56
+ end
57
+
58
+ it "Float#subtract_percent" do
59
+ expect(1.0.subtract_percent(10)).to eq 0.9
60
+ expect(10.4.subtract_percent(10)).to eq 9.360000000000001
61
+ expect(25.2.subtract_percent(5)).to eq 23.939999999999998
62
+ expect(76.6.subtract_percent(40)).to eq 45.959999999999994
63
+ expect(1.0.percentage_off(10)).to eq 0.9
64
+ end
65
+
66
+ it "BigDecimal#subtract_percent" do
67
+ expect(12654377184.123123.subtract_percent(10)).to eq 11388939465.710812
68
+ expect(123.129405.subtract_percent(25)).to eq 92.34705375
69
+ expect(123.129405.percentage_off(25)).to eq 92.34705375
70
+ end
71
+
72
+
73
+ it "Fixnum#add_percent" do
74
+ expect(1.add_percent(10)).to eq 1.1
75
+ expect(10.add_percent(10)).to eq 11.0
76
+ expect(25.add_percent(5)).to eq 26.25
77
+ expect(76.add_percent(40)).to eq 106.4
78
+ expect(76.markup_by_percent(40)).to eq 106.4
79
+ expect(200.markup_by_percent(100)).to eq 400
80
+ end
81
+
82
+ it "Bignum#add_percent" do
83
+ expect(12356469787881584554556.add_percent(10)).to eq 1.3592116766669745e+22
84
+ expect(12356469787881584554556.markup_by_percent(10)).to eq 1.3592116766669745e+22
85
+ end
86
+
87
+ it "Float#add_percent" do
88
+ expect(1.5.add_percent(100)).to eq 3.0
89
+ expect(10.4.add_percent(10)).to eq 11.440000000000001
90
+ expect(25.2.add_percent(5)).to eq 26.46
91
+ expect(76.6.add_percent(40)).to eq 107.24
92
+ expect(1.5.markup_by_percent(100)).to eq 3.0
93
+ end
94
+
95
+ it "BigDecimal#add_percent" do
96
+ expect(12654377184.123123.add_percent(10)).to eq 13919814902.535435
97
+ expect(123.129405.add_percent(25)).to eq 153.91175625
98
+ expect(123.129405.markup_by_percent(25)).to eq 153.91175625
99
+ end
100
+
101
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: finishing_moves
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Koehl
@@ -103,9 +103,9 @@ files:
103
103
  - lib/finishing_moves/array.rb
104
104
  - lib/finishing_moves/enumerable.rb
105
105
  - lib/finishing_moves/fiscal_logic.rb
106
- - lib/finishing_moves/fixnum.rb
107
106
  - lib/finishing_moves/hash.rb
108
107
  - lib/finishing_moves/kernel.rb
108
+ - lib/finishing_moves/numeric.rb
109
109
  - lib/finishing_moves/object.rb
110
110
  - lib/finishing_moves/string.rb
111
111
  - lib/finishing_moves/to_bool.rb
@@ -114,9 +114,9 @@ files:
114
114
  - spec/array_spec.rb
115
115
  - spec/enumerable_spec.rb
116
116
  - spec/fiscal_logic_spec.rb
117
- - spec/fixnum_spec.rb
118
117
  - spec/hash_spec.rb
119
118
  - spec/kernel_spec.rb
119
+ - spec/numeric_spec.rb
120
120
  - spec/object_spec.rb
121
121
  - spec/spec_helper.rb
122
122
  - spec/string_spec.rb
@@ -160,9 +160,9 @@ test_files:
160
160
  - spec/array_spec.rb
161
161
  - spec/enumerable_spec.rb
162
162
  - spec/fiscal_logic_spec.rb
163
- - spec/fixnum_spec.rb
164
163
  - spec/hash_spec.rb
165
164
  - spec/kernel_spec.rb
165
+ - spec/numeric_spec.rb
166
166
  - spec/object_spec.rb
167
167
  - spec/spec_helper.rb
168
168
  - spec/string_spec.rb
@@ -1,20 +0,0 @@
1
- class Integer
2
- def length
3
- Math.log10(self.abs).to_i + 1
4
- end
5
- alias_method :digits, :length
6
- end
7
-
8
- class Float
9
- def length
10
- raise ArgumentError.new("Cannot get length: \"#{self}\" is not an integer")
11
- end
12
- alias_method :digits, :length
13
- end
14
-
15
- class BigDecimal
16
- def length
17
- raise ArgumentError.new("Cannot get length: \"#{self}\" is not an integer")
18
- end
19
- alias_method :digits, :length
20
- end
@@ -1,43 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Count number length" do
4
-
5
- it "Fixnum#length" do
6
- expect(1.length).to eq 1
7
- expect(5.length).to eq 1
8
- expect(9.length).to eq 1
9
- expect(90.length).to eq 2
10
- expect(900.length).to eq 3
11
- expect(9000.length).to eq 4
12
- expect(-9000.length).to eq 4
13
- # alias
14
- expect(-9000.digits).to eq 4
15
- end
16
-
17
- it "Bignum#length" do
18
- expect(12356469787881584554556.length).to eq 23
19
- expect(-12356469787881584554556.length).to eq 23
20
- # alias
21
- expect(-12356469787881584554556.digits).to eq 23
22
- end
23
-
24
- it "Float#length" do
25
- expect{ 0.0.length }.to raise_error(ArgumentError)
26
- expect{ 1.0.length }.to raise_error(ArgumentError)
27
- expect{ -1.0.length }.to raise_error(ArgumentError)
28
- expect{ 3.14.length }.to raise_error(ArgumentError)
29
- expect{ 12356469.987.length }.to raise_error(ArgumentError)
30
- # alias
31
- expect{ 12356469.987.digits }.to raise_error(ArgumentError)
32
- end
33
-
34
- it "BigDecimal#length" do
35
- expect{ 1265437718438866624512.123.length }.to raise_error(ArgumentError)
36
- expect{ -1265437718438866624512.123.length }.to raise_error(ArgumentError)
37
- expect{ 0.9999999999999062.length }.to raise_error(ArgumentError)
38
- expect{ -0.9999999999999062.length }.to raise_error(ArgumentError)
39
- # alias
40
- expect{ -0.9999999999999062.digits }.to raise_error(ArgumentError)
41
- end
42
-
43
- end