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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c38b59a2f62cb429b0015232e5d9eec8189cf5b6
4
- data.tar.gz: 2a0480fc1fd8fca5beef9e87cec5ca4d502d56c6
3
+ metadata.gz: 880f4306056a6c39e02e55ef0185d48f68f1b12c
4
+ data.tar.gz: dabbf97226e73bb5f83370e92b06802aa2a11593
5
5
  SHA512:
6
- metadata.gz: 007b4371f4f04f9a6e97d6db725e9c4594be91ce31faa16c67f7e0312bed43e2200254d0fde3c71c0140638f5b00f52216ff4b9636bbf1abe155b03bf0dfc690
7
- data.tar.gz: 4706b9e13cb043c126ce09c0c2a46fad72cfa068d5f838adc5fdf58abcec0b1c7c364b5aca37ba79154a56accd11b1a4e50ba2fb67e5c0a65c43e3296eca5102
6
+ metadata.gz: b545f4f83b4613dab3db78ccb5ced4441496505a2ed968c073075311186ccfbe92a62f81363c30109408dda675b928dd05556e49711b4fe844897f9e9ea45e40
7
+ data.tar.gz: 6ffede83059646431bb7f44b5ed646cbc5a5953bf64a82b81c3dbc37b76503a72b8a0334f7da727b22f4d0c9f755596f75fae5d089edd889185674438e426869
@@ -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
 
@@ -1,3 +1,3 @@
1
1
  module DuckPuncher
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -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.2
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-20 00:00:00.000000000 Z
11
+ date: 2014-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler