percentage 1.4.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +8 -0
- data/LICENSE.txt +1 -1
- data/README.md +1 -1
- data/lib/percentage.rb +13 -1
- data/percentage.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d73c317eceabcfd5b4b4f385f7def4664d5e7d827e925d101a306ba404170b69
|
4
|
+
data.tar.gz: 3f225768beb51e4d8a743f2550be17119773ef392550369c2756d603bf448d68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50b8c3ca5f618908e1ea75c2bb5076bf87a27d902781f96267f76954b9ec4481965a3dddc1a2f259b677a151bcf6bd39f48093e42307430335eb459b7270d3e7
|
7
|
+
data.tar.gz: 16e31215f053b38882f6b96e49e8b5c13a106342d7fefc0f4a5a2e87e8ce60aae95f64d5d65b279c3ec2e04e86b6230ca136904140b93c3321079903732b02ac
|
data/CHANGES.md
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# percentage
|
2
2
|
|
3
3
|
![Gem Version](https://badge.fury.io/rb/percentage.svg)
|
4
|
-
![
|
4
|
+
![Test Status](https://github.com/readysteady/percentage/actions/workflows/test.yml/badge.svg)
|
5
5
|
|
6
6
|
|
7
7
|
Ruby gem for working with percentages.
|
data/lib/percentage.rb
CHANGED
@@ -7,6 +7,8 @@ class Percentage
|
|
7
7
|
|
8
8
|
def initialize(value)
|
9
9
|
@value = value
|
10
|
+
|
11
|
+
freeze
|
10
12
|
end
|
11
13
|
|
12
14
|
def to_i
|
@@ -25,6 +27,16 @@ class Percentage
|
|
25
27
|
fractional_value.to_r
|
26
28
|
end
|
27
29
|
|
30
|
+
def to_d
|
31
|
+
if @value.integer?
|
32
|
+
@value.to_d / 100
|
33
|
+
elsif BigDecimal === @value
|
34
|
+
@value
|
35
|
+
else
|
36
|
+
@value.to_d(0)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
28
40
|
def zero?
|
29
41
|
@value.zero?
|
30
42
|
end
|
@@ -115,7 +127,7 @@ def Percentage(object)
|
|
115
127
|
end
|
116
128
|
|
117
129
|
def Percentage.change(a, b)
|
118
|
-
Percentage.new((b - a).to_r / a)
|
130
|
+
Percentage.new((b - a).to_r / a) unless a.zero?
|
119
131
|
end
|
120
132
|
|
121
133
|
class BigDecimal
|
data/percentage.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: percentage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Craft
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Ruby gem for working with percentages
|
14
14
|
email:
|
@@ -46,7 +46,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
requirements: []
|
49
|
-
rubygems_version: 3.
|
49
|
+
rubygems_version: 3.3.3
|
50
50
|
signing_key:
|
51
51
|
specification_version: 4
|
52
52
|
summary: See description
|