friendly_numbers 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +4 -0
- data/lib/friendly_numbers.rb +10 -0
- data/lib/friendly_numbers/seconds_to_time.rb +27 -0
- data/lib/friendly_numbers/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97dfbb299d7c618df8fa9acfc1345de6a55697ea
|
4
|
+
data.tar.gz: f98f23f9c9636ae41eefc3ffc0730235e1dc0250
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d057dd64cd6ea14272cfcc2b5b13004735e866063596313bc5e8eb3b709e130010e50f759169e335aa60f1f19c6b241729349d2cde2d2deab43e7954f557617
|
7
|
+
data.tar.gz: aae84bbd59e47d0bcf39e822f1be3adef8f7ef0c49574a6a0b088a98a6b66492cc137aaada0d8d3a827ff8c5beaeab01cefd232e0a371423e856de95a2c8be0b
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -31,6 +31,10 @@ To format a value as a human file size:
|
|
31
31
|
|
32
32
|
FriendlyNumbers.number_to_human_size 12345.67 # => "12.056 KB"
|
33
33
|
|
34
|
+
To format time in seconds to an elapsed time:
|
35
|
+
|
36
|
+
FriendlyNumbers.seconds_to_time(65) # => "1m 5s"
|
37
|
+
|
34
38
|
Also conveniently aliased under the `Friendly` namespace.
|
35
39
|
|
36
40
|
## Development
|
data/lib/friendly_numbers.rb
CHANGED
@@ -2,6 +2,7 @@ require "friendly_numbers/version"
|
|
2
2
|
require "friendly_numbers/number_to_currency"
|
3
3
|
require "friendly_numbers/number_to_human_size"
|
4
4
|
require "friendly_numbers/number_to_percentage"
|
5
|
+
require "friendly_numbers/seconds_to_time"
|
5
6
|
|
6
7
|
module FriendlyNumbers
|
7
8
|
module_function
|
@@ -32,6 +33,15 @@ module FriendlyNumbers
|
|
32
33
|
def number_to_percentage(value, options = {})
|
33
34
|
NumberToPercentage.convert(value, options)
|
34
35
|
end
|
36
|
+
|
37
|
+
# Convert Seconds to an elapsed time
|
38
|
+
#
|
39
|
+
# Options:
|
40
|
+
# format:: a callable object that receives hours, minutes, seconds as
|
41
|
+
# arguments
|
42
|
+
def seconds_to_time(seconds, options = {})
|
43
|
+
SecondsToTime.convert(seconds, options)
|
44
|
+
end
|
35
45
|
end
|
36
46
|
|
37
47
|
Friendly = FriendlyNumbers
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module FriendlyNumbers
|
2
|
+
module SecondsToTime
|
3
|
+
DEFAULTS = {
|
4
|
+
format: ->(hours, minutes, seconds) {
|
5
|
+
fields = []
|
6
|
+
fields.push("#{hours}h") unless hours.zero?
|
7
|
+
fields.push("#{minutes}m") unless minutes.zero?
|
8
|
+
fields.push("#{seconds}s") if seconds
|
9
|
+
|
10
|
+
fields.join(" ")
|
11
|
+
}
|
12
|
+
}
|
13
|
+
|
14
|
+
module_function
|
15
|
+
|
16
|
+
def convert(seconds, options) # :nodoc:
|
17
|
+
options = DEFAULTS.merge(options)
|
18
|
+
|
19
|
+
minutes, seconds = seconds.divmod(60)
|
20
|
+
hours, minutes = minutes.divmod(60)
|
21
|
+
|
22
|
+
if options[:format].respond_to?(:call)
|
23
|
+
options[:format].call(hours, minutes, seconds)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: friendly_numbers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Daniels
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -65,6 +65,7 @@ extra_rdoc_files: []
|
|
65
65
|
files:
|
66
66
|
- ".gitignore"
|
67
67
|
- ".travis.yml"
|
68
|
+
- CHANGELOG.md
|
68
69
|
- Gemfile
|
69
70
|
- LICENSE.txt
|
70
71
|
- README.md
|
@@ -76,6 +77,7 @@ files:
|
|
76
77
|
- lib/friendly_numbers/number_to_currency.rb
|
77
78
|
- lib/friendly_numbers/number_to_human_size.rb
|
78
79
|
- lib/friendly_numbers/number_to_percentage.rb
|
80
|
+
- lib/friendly_numbers/seconds_to_time.rb
|
79
81
|
- lib/friendly_numbers/version.rb
|
80
82
|
homepage: https://github.com/adam12/friendly_numbers
|
81
83
|
licenses:
|