percentage 2.1.1 → 2.3.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 +16 -0
- data/LICENSE.txt +1 -1
- data/lib/percentage.rb +23 -0
- data/percentage.gemspec +4 -4
- metadata +9 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3962a510e791ec11f17b93dc34bb162d7af6129a5f4cd8a37bada8eb9abab85
|
4
|
+
data.tar.gz: 7fe5102660e503e2908a2fa67907c8678d947cf64b33dee12c186f0f33d60628
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a171aa1ac38e246bd24ea9fde11f5c4f5a8fec689b1942b19a7625ffd4b9fa2abf0280cf908a42c66cf7b404ecb6c0275f09b9478d5f82c0cce54e9669d3a4d8
|
7
|
+
data.tar.gz: 8c669769c44e568ef1356d939dfda3b7f59137255fbcd8e9221a55a0b9181393bb99204769ea17e771ee07849753b04c94e29e0618d7976f406a93fdc278568c
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
# 2.3.0
|
2
|
+
|
3
|
+
* **Required ruby version is now 2.5.0**
|
4
|
+
|
5
|
+
* Added Percentage#nonzero?
|
6
|
+
|
7
|
+
* Added Percentage#inspect
|
8
|
+
|
9
|
+
# 2.2.0
|
10
|
+
|
11
|
+
* Added Rational#to_percentage
|
12
|
+
|
13
|
+
* Added Rational#percent_of
|
14
|
+
|
15
|
+
* Added Rational#as_percentage_of
|
16
|
+
|
1
17
|
# 2.1.1
|
2
18
|
|
3
19
|
* Added bigdecimal gem dependency (thanks @orien)
|
data/LICENSE.txt
CHANGED
data/lib/percentage.rb
CHANGED
@@ -41,6 +41,11 @@ class Percentage
|
|
41
41
|
@value.zero?
|
42
42
|
end
|
43
43
|
|
44
|
+
def nonzero?
|
45
|
+
return if @value.zero?
|
46
|
+
self
|
47
|
+
end
|
48
|
+
|
44
49
|
def <=>(object)
|
45
50
|
if self.class === object
|
46
51
|
fractional_value <=> object.fractional_value
|
@@ -115,6 +120,10 @@ class Percentage
|
|
115
120
|
@value.negative?
|
116
121
|
end
|
117
122
|
|
123
|
+
def inspect
|
124
|
+
"<Percentage: value=#{value.inspect}>"
|
125
|
+
end
|
126
|
+
|
118
127
|
protected
|
119
128
|
|
120
129
|
def fractional_value
|
@@ -142,6 +151,20 @@ def Percentage.change(a, b)
|
|
142
151
|
Percentage.new((b - a).to_r / a) unless a.zero?
|
143
152
|
end
|
144
153
|
|
154
|
+
class Rational
|
155
|
+
def to_percentage
|
156
|
+
Percentage(self)
|
157
|
+
end
|
158
|
+
|
159
|
+
def percent_of(n)
|
160
|
+
n * Percentage(self)
|
161
|
+
end
|
162
|
+
|
163
|
+
def as_percentage_of(n)
|
164
|
+
Percentage.new(self / n)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
145
168
|
class BigDecimal
|
146
169
|
def to_percentage
|
147
170
|
Percentage(self)
|
data/percentage.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'percentage'
|
3
|
-
s.version = '2.
|
3
|
+
s.version = '2.3.0'
|
4
4
|
s.license = 'LGPL-3.0'
|
5
5
|
s.platform = Gem::Platform::RUBY
|
6
6
|
s.authors = ['Tim Craft']
|
7
|
-
s.email = ['
|
7
|
+
s.email = ['email@timcraft.com']
|
8
8
|
s.homepage = 'https://github.com/readysteady/percentage'
|
9
9
|
s.description = 'Ruby gem for working with percentages'
|
10
10
|
s.summary = 'See description'
|
11
11
|
s.files = Dir.glob('lib/**/*.rb') + %w[CHANGES.md LICENSE.txt README.md percentage.gemspec]
|
12
|
-
s.required_ruby_version = '>=
|
12
|
+
s.required_ruby_version = '>= 2.5.0'
|
13
13
|
s.require_path = 'lib'
|
14
14
|
s.metadata = {
|
15
15
|
'homepage' => 'https://github.com/readysteady/percentage',
|
@@ -17,5 +17,5 @@ Gem::Specification.new do |s|
|
|
17
17
|
'bug_tracker_uri' => 'https://github.com/readysteady/percentage/issues',
|
18
18
|
'changelog_uri' => 'https://github.com/readysteady/percentage/blob/main/CHANGES.md'
|
19
19
|
}
|
20
|
-
s.
|
20
|
+
s.add_dependency 'bigdecimal', '~> 3'
|
21
21
|
end
|
metadata
CHANGED
@@ -1,32 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: percentage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Craft
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: bigdecimal
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
16
15
|
requirements:
|
17
|
-
- - "
|
16
|
+
- - "~>"
|
18
17
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
18
|
+
version: '3'
|
20
19
|
type: :runtime
|
21
20
|
prerelease: false
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
23
22
|
requirements:
|
24
|
-
- - "
|
23
|
+
- - "~>"
|
25
24
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
25
|
+
version: '3'
|
27
26
|
description: Ruby gem for working with percentages
|
28
27
|
email:
|
29
|
-
-
|
28
|
+
- email@timcraft.com
|
30
29
|
executables: []
|
31
30
|
extensions: []
|
32
31
|
extra_rdoc_files: []
|
@@ -45,7 +44,6 @@ metadata:
|
|
45
44
|
source_code_uri: https://github.com/readysteady/percentage
|
46
45
|
bug_tracker_uri: https://github.com/readysteady/percentage/issues
|
47
46
|
changelog_uri: https://github.com/readysteady/percentage/blob/main/CHANGES.md
|
48
|
-
post_install_message:
|
49
47
|
rdoc_options: []
|
50
48
|
require_paths:
|
51
49
|
- lib
|
@@ -53,15 +51,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
53
51
|
requirements:
|
54
52
|
- - ">="
|
55
53
|
- !ruby/object:Gem::Version
|
56
|
-
version:
|
54
|
+
version: 2.5.0
|
57
55
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
56
|
requirements:
|
59
57
|
- - ">="
|
60
58
|
- !ruby/object:Gem::Version
|
61
59
|
version: '0'
|
62
60
|
requirements: []
|
63
|
-
rubygems_version: 3.
|
64
|
-
signing_key:
|
61
|
+
rubygems_version: 3.6.2
|
65
62
|
specification_version: 4
|
66
63
|
summary: See description
|
67
64
|
test_files: []
|