duck_puncher 0.0.4 → 0.0.6
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/README.md +9 -1
- data/lib/duck_puncher.rb +1 -0
- data/lib/duck_puncher/numeric.rb +22 -4
- data/lib/duck_puncher/string.rb +9 -0
- data/lib/duck_puncher/version.rb +1 -1
- data/test/duck_puncher/numeric_test.rb +14 -0
- data/test/duck_puncher/string_test.rb +10 -0
- metadata +12 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eacd12db4d97e6d70b3c7dcaa4a01850f287364d
|
4
|
+
data.tar.gz: 57312f98a87dc5f07aa93ac1783e929fd65bb621
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47457f129e09dc4489aaf495f77f33535f34625619a4d672edb9645158ca6350e7d0af36812eb1aae022ddfe27794f73223c59cbefe5b82564cc760cc659723e
|
7
|
+
data.tar.gz: 6c697d9668c2e4d2c71e2fc9eb9426586b800f780098ad133ba413c69173dc1915cfd24283034ebc19283c3ec37a6add55df50c4ae8f54b6cd17bfa8d032383d
|
data/README.md
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
# DuckPuncher
|
2
2
|
|
3
|
-
|
3
|
+
Currently have the following punches in our repertoire:
|
4
|
+
|
5
|
+
* Array#m - alias for `map(&:)`, usage: `[1].m(:succ)`
|
6
|
+
* Hash#seek - usage: `{a: 1, b: {c: 2}}.seek(:b, :c) #=> 2`
|
7
|
+
* Numeric#to_currency - usage: `25.245.to_currency #=> '25.25'`
|
8
|
+
* Numeric#to_duration - usage `10_000.to_duration #=> '2 h 46 min'`
|
9
|
+
* Numeric#to_time_ago - usage `10_000.to_time_ago #=> '2 hours ago'`
|
10
|
+
* Numeric#to_rad - usage `10.15.to_rad #=> 0.17715091907742445`
|
11
|
+
* String#pluralize - usage `'hour'.pluralize(2) #=> 'hours'`
|
4
12
|
|
5
13
|
## Installation
|
6
14
|
|
data/lib/duck_puncher.rb
CHANGED
data/lib/duck_puncher/numeric.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module DuckPuncher
|
2
2
|
module Numeric
|
3
|
-
def to_currency
|
4
|
-
|
3
|
+
def to_currency(prefix = '')
|
4
|
+
"#{prefix}%.2f" % self.round(2)
|
5
5
|
end
|
6
6
|
|
7
|
-
def to_duration(seconds=false)
|
8
|
-
secs =
|
7
|
+
def to_duration(seconds = false)
|
8
|
+
secs = to_i
|
9
9
|
mins = secs / 60
|
10
10
|
hours = mins / 60
|
11
11
|
buffer = ''
|
@@ -23,6 +23,24 @@ module DuckPuncher
|
|
23
23
|
buffer
|
24
24
|
end
|
25
25
|
|
26
|
+
def to_time_ago
|
27
|
+
secs = to_i
|
28
|
+
mins = secs / 60
|
29
|
+
hours = mins / 60
|
30
|
+
days = hours / 24
|
31
|
+
buffer = ''
|
32
|
+
if days > 0
|
33
|
+
buffer << "#{days} #{'day'.pluralize(days)}"
|
34
|
+
elsif hours > 0
|
35
|
+
buffer << "#{hours} #{'hour'.pluralize(hours)}"
|
36
|
+
elsif mins > 0
|
37
|
+
buffer << "#{mins} #{'minute'.pluralize(mins)}"
|
38
|
+
elsif secs >= 0
|
39
|
+
buffer << "less than a minute"
|
40
|
+
end
|
41
|
+
buffer << ' ago'
|
42
|
+
end
|
43
|
+
|
26
44
|
def to_rad
|
27
45
|
self / 180 * Math::PI
|
28
46
|
end
|
data/lib/duck_puncher/version.rb
CHANGED
@@ -7,6 +7,7 @@ class NumericTest < MiniTest::Unit::TestCase
|
|
7
7
|
assert_equal '25.00', 25.to_currency
|
8
8
|
assert_equal '25.20', 25.2.to_currency
|
9
9
|
assert_equal '25.25', 25.245.to_currency
|
10
|
+
assert_equal '$25.25', 25.245.to_currency('$')
|
10
11
|
end
|
11
12
|
|
12
13
|
def test_to_duration
|
@@ -30,4 +31,17 @@ class NumericTest < MiniTest::Unit::TestCase
|
|
30
31
|
assert_equal 0.36035409894869713, 20.646769.to_rad
|
31
32
|
assert_equal -2.730392366234936, -156.439959.to_rad
|
32
33
|
end
|
34
|
+
|
35
|
+
def test_to_time_ago
|
36
|
+
assert_equal 'less than a minute ago', 10.to_time_ago
|
37
|
+
assert_equal '1 minute ago', 100.to_time_ago
|
38
|
+
assert_equal '2 minutes ago', 130.to_time_ago
|
39
|
+
assert_equal '16 minutes ago', 1_000.to_time_ago
|
40
|
+
assert_equal '1 hour ago', 3_600.to_time_ago
|
41
|
+
assert_equal '1 hour ago', 4_600.to_time_ago
|
42
|
+
assert_equal '2 hours ago', 7_300.to_time_ago
|
43
|
+
assert_equal '1 day ago', 86_400.to_time_ago
|
44
|
+
assert_equal '1 day ago', 100_000.to_time_ago
|
45
|
+
assert_equal '2 days ago', 180_000.to_time_ago
|
46
|
+
end
|
33
47
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'duck_puncher'
|
3
|
+
|
4
|
+
class HashTest < MiniTest::Unit::TestCase
|
5
|
+
def test_pluralize
|
6
|
+
assert_equal 'hour'.pluralize(1), 'hour'
|
7
|
+
assert_equal 'hour'.pluralize(0), 'hours'
|
8
|
+
assert_equal 'hour'.pluralize(2), 'hours'
|
9
|
+
end
|
10
|
+
end
|
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
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.6
|
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-
|
11
|
+
date: 2014-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.3'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
description: Duck punches Ruby with some of my favorite class extensions
|
@@ -45,7 +45,7 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
-
- .gitignore
|
48
|
+
- ".gitignore"
|
49
49
|
- Gemfile
|
50
50
|
- LICENSE.txt
|
51
51
|
- README.md
|
@@ -55,10 +55,12 @@ files:
|
|
55
55
|
- lib/duck_puncher/array.rb
|
56
56
|
- lib/duck_puncher/hash.rb
|
57
57
|
- lib/duck_puncher/numeric.rb
|
58
|
+
- lib/duck_puncher/string.rb
|
58
59
|
- lib/duck_puncher/version.rb
|
59
60
|
- test/duck_puncher/array_test.rb
|
60
61
|
- test/duck_puncher/hash_test.rb
|
61
62
|
- test/duck_puncher/numeric_test.rb
|
63
|
+
- test/duck_puncher/string_test.rb
|
62
64
|
homepage: ''
|
63
65
|
licenses:
|
64
66
|
- MIT
|
@@ -69,12 +71,12 @@ require_paths:
|
|
69
71
|
- lib
|
70
72
|
required_ruby_version: !ruby/object:Gem::Requirement
|
71
73
|
requirements:
|
72
|
-
- -
|
74
|
+
- - ">="
|
73
75
|
- !ruby/object:Gem::Version
|
74
76
|
version: '0'
|
75
77
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
78
|
requirements:
|
77
|
-
- -
|
79
|
+
- - ">="
|
78
80
|
- !ruby/object:Gem::Version
|
79
81
|
version: '0'
|
80
82
|
requirements: []
|
@@ -87,4 +89,4 @@ test_files:
|
|
87
89
|
- test/duck_puncher/array_test.rb
|
88
90
|
- test/duck_puncher/hash_test.rb
|
89
91
|
- test/duck_puncher/numeric_test.rb
|
90
|
-
|
92
|
+
- test/duck_puncher/string_test.rb
|