duration-human 0.0.1 → 0.0.2
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 +5 -5
- data/.gitignore +1 -0
- data/.travis.yml +5 -0
- data/README.md +9 -2
- data/Rakefile +1 -1
- data/duration-human.gemspec +5 -5
- data/lib/duration-human.rb +13 -1
- data/test/helper.rb +9 -0
- data/test/test-duration-human.rb +72 -0
- metadata +18 -15
- data/test/plugin/test_filter_email_obfuscate.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 464a4e864b2e676213109b06f469f7f14403935433b1cc0886c01d251b7caac5
|
4
|
+
data.tar.gz: '040586678c0b13ed9e58c65c5920327952f5bf7c52278af84fde2c88943ff143'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ec7104bd0396190de7e2720557e6f854284c5819491a26396ae86e8001dbcc5f29ea3938e8a550f16f56cf53e9ec2989a30dab8abd2f3f8b891518b767a1419
|
7
|
+
data.tar.gz: 0f63efa55396f147720bce443e3514f079782c29eaab0e2903129c294b64eb83bb4c507bb3407fd39c1362e163636ffac99dffbc85d0942cca588a87d9b1e18f
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
**/*.gem
|
data/README.md
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
# duration-human
|
2
2
|
|
3
|
+
[](https://badge.fury.io/rb/duration-human)
|
4
|
+
|
3
5
|
Ruby module to entend Numeric class with a method to convert a number of seconds to a human readable time duration.
|
4
6
|
|
7
|
+
*Requires Ruby 2.4.0 or newer. Tested with Ruby 2.4, 2.5 & 2.6*
|
8
|
+
|
5
9
|
For example:
|
6
10
|
|
7
11
|
```
|
@@ -13,7 +17,9 @@ For example:
|
|
13
17
|
349200.duration ==> "4 days and 1 hours"
|
14
18
|
```
|
15
19
|
|
16
|
-
Setting `concise` to `true` in the method arguments will use initials `s`, `m`, `h`, `d` for the units, and omit the word `and`.
|
20
|
+
Setting `concise` to `true` in the method arguments will use initials `s`, `m`, `h`, `d` for the units, and omit the word `and`.
|
21
|
+
|
22
|
+
For example:
|
17
23
|
|
18
24
|
```
|
19
25
|
80.duration(concise: true) ==> "80s"
|
@@ -22,4 +28,5 @@ Setting `concise` to `true` in the method arguments will use initials `s`, `m`,
|
|
22
28
|
349200.duration (concise: true) ==> "4d 1h"
|
23
29
|
```
|
24
30
|
|
25
|
-
The thresholds for
|
31
|
+
The thresholds for changing between seconds, minutes, hours and days is "2". For example, 80 is less than 2 minutes, so it is "80 seconds". 200 is more than 2 minutes, so it is "3 minutes and 20 seconds" instead of "200 seconds".
|
32
|
+
|
data/Rakefile
CHANGED
data/duration-human.gemspec
CHANGED
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |spec|
|
5
5
|
spec.name = "duration-human"
|
6
|
-
spec.version = "0.0.
|
6
|
+
spec.version = "0.0.2"
|
7
7
|
spec.authors = ["JamesJJ"]
|
8
8
|
spec.email = ["jj@fcg.fyi"]
|
9
9
|
|
@@ -19,9 +19,9 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
20
|
spec.test_files = test_files
|
21
21
|
spec.require_paths = ["lib"]
|
22
|
-
spec.required_ruby_version = '>= 2.
|
22
|
+
spec.required_ruby_version = '>= 2.4.0'
|
23
23
|
|
24
|
-
spec.add_development_dependency "bundler", "
|
25
|
-
spec.add_development_dependency "rake", "~> 12.
|
26
|
-
spec.add_development_dependency "test-unit", "~> 3.
|
24
|
+
spec.add_development_dependency "bundler", ">= 1.0"
|
25
|
+
spec.add_development_dependency "rake", "~> 12.3"
|
26
|
+
spec.add_development_dependency "test-unit", "~> 3.3"
|
27
27
|
end
|
data/lib/duration-human.rb
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
class Numeric
|
2
2
|
def duration(concise: false)
|
3
|
-
|
3
|
+
|
4
|
+
if self.infinite?
|
5
|
+
return (concise ? 8734.chr(Encoding::UTF_8) : "an infinitely long time")
|
6
|
+
end
|
7
|
+
|
8
|
+
begin
|
9
|
+
seconds = self.to_int
|
10
|
+
rescue FloatDomainError
|
11
|
+
return ""
|
12
|
+
end
|
13
|
+
|
4
14
|
minutes = seconds / 60
|
5
15
|
hours = minutes / 60
|
6
16
|
days = hours / 24
|
@@ -13,6 +23,8 @@ class Numeric
|
|
13
23
|
concise ? "#{minutes}m #{seconds % 60}s" : "#{minutes} minutes and #{seconds % 60} seconds"
|
14
24
|
elsif seconds >= 0
|
15
25
|
concise ? "#{seconds}s" : "#{seconds} seconds"
|
26
|
+
else
|
27
|
+
(concise ? "-" : "minus " ) + seconds.abs.duration(concise: concise)
|
16
28
|
end
|
17
29
|
end
|
18
30
|
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require_relative "../lib/duration-human.rb"
|
2
|
+
require "test/unit"
|
3
|
+
|
4
|
+
class TestNumeric < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_long_seconds
|
7
|
+
assert_equal("70 seconds", 70.duration)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_long_minutes
|
11
|
+
assert_equal("72 minutes and 12 seconds", 4332.duration)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_long_hours
|
15
|
+
assert_equal("26 hours and 30 minutes", 95400.duration)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_long_days
|
19
|
+
assert_equal("2 days and 2 hours", 180000.duration)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_concise_seconds
|
23
|
+
assert_equal("70s", 70.duration(concise: true))
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_concise_minutes
|
27
|
+
assert_equal("72m 12s", 4332.duration(concise: true))
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_concise_hours
|
31
|
+
assert_equal("26h 30m", 95400.duration(concise: true))
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_concise_days
|
35
|
+
assert_equal("2d 2h", 180000.duration(concise: true))
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_float
|
39
|
+
assert_equal("3 seconds", 3.456.duration)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_rational
|
43
|
+
assert_equal("4 seconds", (9 / 2).duration)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_zero
|
47
|
+
assert_equal("0 seconds", 0.duration)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_nan
|
51
|
+
assert_equal("", (0 / 0.0).duration)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_long_infinity
|
55
|
+
assert_equal("an infinitely long time", (1 / 0.0).duration)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_concise_infinity
|
59
|
+
assert_equal(8734.chr(Encoding::UTF_8), (1 / 0.0).duration(concise: true)) # "∞"
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_long_negative
|
63
|
+
assert_equal("minus 4 seconds", -4.duration)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_concise_negative
|
67
|
+
assert_equal("-6s", -6.duration(concise: true))
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
|
metadata
CHANGED
@@ -1,57 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: duration-human
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JamesJJ
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-17 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
|
-
version: '1.
|
19
|
+
version: '1.0'
|
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
|
-
version: '1.
|
26
|
+
version: '1.0'
|
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
|
-
version: '12.
|
33
|
+
version: '12.3'
|
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
|
-
version: '12.
|
40
|
+
version: '12.3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: test-unit
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '3.
|
47
|
+
version: '3.3'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '3.
|
54
|
+
version: '3.3'
|
55
55
|
description:
|
56
56
|
email:
|
57
57
|
- jj@fcg.fyi
|
@@ -59,13 +59,16 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
62
64
|
- Gemfile
|
63
65
|
- LICENSE
|
64
66
|
- README.md
|
65
67
|
- Rakefile
|
66
68
|
- duration-human.gemspec
|
67
69
|
- lib/duration-human.rb
|
68
|
-
- test/
|
70
|
+
- test/helper.rb
|
71
|
+
- test/test-duration-human.rb
|
69
72
|
- tool/build_and_push_to_rubygems.sh
|
70
73
|
homepage: https://github.com/JamesJJ/ruby-duration-human
|
71
74
|
licenses:
|
@@ -79,17 +82,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
79
82
|
requirements:
|
80
83
|
- - ">="
|
81
84
|
- !ruby/object:Gem::Version
|
82
|
-
version: 2.
|
85
|
+
version: 2.4.0
|
83
86
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
87
|
requirements:
|
85
88
|
- - ">="
|
86
89
|
- !ruby/object:Gem::Version
|
87
90
|
version: '0'
|
88
91
|
requirements: []
|
89
|
-
|
90
|
-
rubygems_version: 2.5.2.3
|
92
|
+
rubygems_version: 3.0.3
|
91
93
|
signing_key:
|
92
94
|
specification_version: 4
|
93
95
|
summary: Extend Numeric with method to provide duration as a human readable string
|
94
96
|
test_files:
|
95
|
-
- test/
|
97
|
+
- test/helper.rb
|
98
|
+
- test/test-duration-human.rb
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
require "fluent/plugin/filter_email_obfuscate.rb"
|
3
|
-
|
4
|
-
class EmailObfuscateFilterTest < Test::Unit::TestCase
|
5
|
-
setup do
|
6
|
-
Fluent::Test.setup
|
7
|
-
end
|
8
|
-
|
9
|
-
test "failure" do
|
10
|
-
flunk
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def create_driver(conf)
|
16
|
-
Fluent::Test::Driver::Filter.new(Fluent::Plugin::EmailObfuscateFilter).configure(conf)
|
17
|
-
end
|
18
|
-
end
|