bootstripe 0.2.12 → 0.2.13
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/bootstripe/number_additions.rb +14 -13
- data/lib/bootstripe/version.rb +1 -1
- data/spec/number_additions_spec.rb +7 -1
- metadata +10 -5
@@ -4,32 +4,33 @@ class Numeric
|
|
4
4
|
[[self, min].max, max].min
|
5
5
|
end
|
6
6
|
|
7
|
-
def to_period(detailed = true)
|
7
|
+
def to_period(detailed = true, abbreviated = true)
|
8
8
|
total_seconds = self.to_i
|
9
|
-
|
9
|
+
|
10
10
|
days = total_seconds / 86400
|
11
11
|
hours = (total_seconds / 3600) - (days * 24)
|
12
12
|
minutes = (total_seconds / 60) - (hours * 60) - (days * 1440)
|
13
13
|
seconds = total_seconds % 60
|
14
|
-
|
15
|
-
|
16
|
-
display_concat = ''
|
14
|
+
|
15
|
+
elements = []
|
17
16
|
if days > 0
|
18
|
-
|
19
|
-
|
17
|
+
suffix = abbreviated ? 'd' : (days == 1 ? ' day' : ' days')
|
18
|
+
elements << "#{days}#{suffix}"
|
20
19
|
end
|
21
20
|
if hours > 0
|
22
|
-
|
23
|
-
|
21
|
+
suffix = abbreviated ? 'h' : (hours == 1 ? ' hour' : ' hours')
|
22
|
+
elements << "#{hours}#{suffix}"
|
24
23
|
end
|
25
24
|
if minutes > 0 and (detailed or days == 0)
|
26
|
-
|
27
|
-
|
25
|
+
suffix = abbreviated ? 'm' : (minutes == 1 ? ' minute' : ' minutes')
|
26
|
+
elements << "#{minutes}#{suffix}"
|
28
27
|
end
|
29
28
|
if seconds > 0 and (detailed or (days == 0 and hours == 0))
|
30
|
-
|
29
|
+
suffix = abbreviated ? 's' : (days == 1 ? ' seconds' : ' second')
|
30
|
+
elements << "#{seconds}#{suffix}"
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
|
+
elements.join(abbreviated ? ' ' : ', ')
|
33
34
|
end
|
34
35
|
|
35
36
|
def to_formatted_time
|
data/lib/bootstripe/version.rb
CHANGED
@@ -14,10 +14,16 @@ describe Numeric do
|
|
14
14
|
(673.2).to_formatted_time.should eq '11:13'
|
15
15
|
end
|
16
16
|
|
17
|
-
it 'should periods accurately' do
|
17
|
+
it 'should describe periods accurately' do
|
18
18
|
3600.to_period.should eq '1h'
|
19
19
|
7260.to_period.should eq '2h 1m'
|
20
20
|
(86400 + 10).to_period.should eq '1d 10s'
|
21
21
|
end
|
22
22
|
|
23
|
+
it 'should describe periods non-abbreviated' do
|
24
|
+
3600.to_period(true, false).should eq '1 hour'
|
25
|
+
7260.to_period(true, false).should eq '2 hours, 1 minute'
|
26
|
+
(86400 + 10).to_period(true, false).should eq '1 day, 10 seconds'
|
27
|
+
end
|
28
|
+
|
23
29
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bootstripe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.13
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-09-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,12 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
description: A handful of useful additions for Ruby
|
26
31
|
email:
|
27
32
|
- mike@bytebin.com
|
@@ -68,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
73
|
version: '0'
|
69
74
|
requirements: []
|
70
75
|
rubyforge_project: bootstripe
|
71
|
-
rubygems_version: 1.8.
|
76
|
+
rubygems_version: 1.8.23
|
72
77
|
signing_key:
|
73
78
|
specification_version: 3
|
74
79
|
summary: A handful of useful additions for Ruby
|