duck_puncher 0.0.2 → 0.0.3
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 +4 -4
- data/lib/duck_puncher/numeric.rb +19 -0
- data/lib/duck_puncher/version.rb +1 -1
- data/test/duck_puncher/numeric_test.rb +15 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 880f4306056a6c39e02e55ef0185d48f68f1b12c
|
4
|
+
data.tar.gz: dabbf97226e73bb5f83370e92b06802aa2a11593
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b545f4f83b4613dab3db78ccb5ced4441496505a2ed968c073075311186ccfbe92a62f81363c30109408dda675b928dd05556e49711b4fe844897f9e9ea45e40
|
7
|
+
data.tar.gz: 6ffede83059646431bb7f44b5ed646cbc5a5953bf64a82b81c3dbc37b76503a72b8a0334f7da727b22f4d0c9f755596f75fae5d089edd889185674438e426869
|
data/lib/duck_puncher/numeric.rb
CHANGED
@@ -3,6 +3,25 @@ module DuckPuncher
|
|
3
3
|
def to_currency
|
4
4
|
'%.2f' % self.round(2)
|
5
5
|
end
|
6
|
+
|
7
|
+
def to_duration(seconds=false)
|
8
|
+
secs = self.to_i
|
9
|
+
mins = secs / 60
|
10
|
+
hours = mins / 60
|
11
|
+
buffer = ''
|
12
|
+
if hours > 0
|
13
|
+
num_mins = mins % 60
|
14
|
+
buffer << "#{hours} h"
|
15
|
+
buffer << " #{num_mins} min" unless num_mins.zero?
|
16
|
+
elsif mins > 0
|
17
|
+
num_secs = secs % 60
|
18
|
+
buffer << "#{mins} min"
|
19
|
+
buffer << " #{num_secs} s" if seconds && num_secs.nonzero?
|
20
|
+
elsif seconds && secs >= 0
|
21
|
+
buffer << "#{secs} s"
|
22
|
+
end
|
23
|
+
buffer
|
24
|
+
end
|
6
25
|
end
|
7
26
|
end
|
8
27
|
|
data/lib/duck_puncher/version.rb
CHANGED
@@ -8,4 +8,19 @@ class NumericTest < MiniTest::Unit::TestCase
|
|
8
8
|
assert_equal '25.20', 25.2.to_currency
|
9
9
|
assert_equal '25.25', 25.245.to_currency
|
10
10
|
end
|
11
|
+
|
12
|
+
def test_to_duration
|
13
|
+
assert_equal '', 10.to_duration
|
14
|
+
assert_equal '1 min', 100.to_duration
|
15
|
+
assert_equal '16 min', 1_000.to_duration
|
16
|
+
assert_equal '2 h 46 min', 10_000.to_duration
|
17
|
+
assert_equal '27 h 46 min', 100_000.to_duration
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_to_duration_with_seconds
|
21
|
+
assert_equal '10 s', 10.to_duration(true)
|
22
|
+
assert_equal '1 min 40 s', 100.to_duration(true)
|
23
|
+
assert_equal '16 min 40 s', 1_000.to_duration(true)
|
24
|
+
assert_equal '2 h 46 min', 10_000.to_duration(true)
|
25
|
+
end
|
11
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: duck_puncher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Buckley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|