epitools 0.5.41 → 0.5.42

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: 11d3c2b4e8f320ff75a614b617aa3571a8e4a89c
4
- data.tar.gz: a33291591096efd021c4d8647d5e73e23dffa745
3
+ metadata.gz: 2e79467768b0f577f8f5abc4759c803db80c09ef
4
+ data.tar.gz: 3f7dd61e9c7e55ebfa7229f96ebc33eb3e3d7b00
5
5
  SHA512:
6
- metadata.gz: 276e60d3e8028ebf5ebbac51ba8c33575f9c64bfc7997d828c13a8fd2a0a47d23a78e5f6f39b10d2de91cd16d8f7edb6435c842b3e274b0136604bbb9d45ff03
7
- data.tar.gz: 284f2fa58e0fd4dc8e536b66515fce57a61a1fd7035623ea4360ebdf787c97c938f47eff235ca5ab47e4f424ea778e519fe8d0c306a372947a4aa4e3a1adca6f
6
+ metadata.gz: 062d1d28880dc3912788142ec6d9b8e83be4690bb371940c82b68fd8c71986a3b9a14476f2e204b1370e30c42ba82985ea5771b32e97ad10a1a767b8474ec734
7
+ data.tar.gz: 09e27bd437b0dc4a7a1ae64a6c87972251aa10def9b2e34d2a5283e885a95a058a3d7afe711c16db90068a6e98f7d7ea9826a535455763f1f9a70f479ac6343f
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.41
1
+ 0.5.42
@@ -4,8 +4,26 @@ class Numeric
4
4
 
5
5
  def truthy?; self > 0; end
6
6
 
7
- def commatize
8
- to_s.gsub(/(\d)(?=\d{3}+(?:\.|$))(\d{3}\..*)?/,'\1,\2')
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
  #
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epitools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.41
4
+ version: 0.5.42
5
5
  platform: ruby
6
6
  authors:
7
7
  - epitron