epitools 0.5.41 → 0.5.42
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/epitools/core_ext/numbers.rb +20 -2
- data/spec/core_ext_spec.rb +3 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e79467768b0f577f8f5abc4759c803db80c09ef
|
4
|
+
data.tar.gz: 3f7dd61e9c7e55ebfa7229f96ebc33eb3e3d7b00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 062d1d28880dc3912788142ec6d9b8e83be4690bb371940c82b68fd8c71986a3b9a14476f2e204b1370e30c42ba82985ea5771b32e97ad10a1a767b8474ec734
|
7
|
+
data.tar.gz: 09e27bd437b0dc4a7a1ae64a6c87972251aa10def9b2e34d2a5283e885a95a058a3d7afe711c16db90068a6e98f7d7ea9826a535455763f1f9a70f479ac6343f
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.42
|
@@ -4,8 +4,26 @@ class Numeric
|
|
4
4
|
|
5
5
|
def truthy?; self > 0; end
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
#
|
8
|
+
# Convert this number to a string, adding commas between each group of 3 digits.
|
9
|
+
#
|
10
|
+
# (The "char" argument is optional, and specifies what character to use in between
|
11
|
+
# each group of numbers.)
|
12
|
+
#
|
13
|
+
def commatize(char=",")
|
14
|
+
str = self.is_a?(BigDecimal) ? to_s("F") : to_s
|
15
|
+
|
16
|
+
int, frac = str.split(".")
|
17
|
+
int = int.gsub /(\d)(?=\d{3}+(?:\.|$))(\d{3}\..*)?/, "\\1#{char}\\2"
|
18
|
+
|
19
|
+
frac ? "#{int}.#{frac}" : int
|
20
|
+
end
|
21
|
+
|
22
|
+
#
|
23
|
+
# Convert this number to a string, adding underscores between each group of 3 digits.
|
24
|
+
#
|
25
|
+
def underscorize
|
26
|
+
commatize("_")
|
9
27
|
end
|
10
28
|
|
11
29
|
#
|
data/spec/core_ext_spec.rb
CHANGED
@@ -155,6 +155,9 @@ describe Numeric do
|
|
155
155
|
12983287123.commatize.should == "12,983,287,123"
|
156
156
|
-12983287123.commatize.should == "-12,983,287,123"
|
157
157
|
-12983287123.4411.commatize.should == "-12,983,287,123.4411"
|
158
|
+
1111.1234567.commatize.should == "1,111.1234567"
|
159
|
+
BigDecimal.new("1111.1234567").commatize.should == "1,111.1234567"
|
160
|
+
-1234567.1234567.underscorize.should == "-1_234_567.1234567"
|
158
161
|
end
|
159
162
|
|
160
163
|
it "does time things" do
|