duration-human 0.0.1
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 +7 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +25 -0
- data/Rakefile +13 -0
- data/duration-human.gemspec +27 -0
- data/lib/duration-human.rb +18 -0
- data/test/plugin/test_filter_email_obfuscate.rb +18 -0
- data/tool/build_and_push_to_rubygems.sh +7 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c521139dcf3935ee9c6ebaa4823f4b664b977d34
|
4
|
+
data.tar.gz: bcce1587a39b7239a537eb60f69473d9a853250c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9a2157d4ba82544b4aea19ecb97e9e1466eeeefcc8476545af1d7720c9ede4537cada3291db44bb8d7a0a201133b47405b5e8a75b1ead3057bc034ad43f0ab82
|
7
|
+
data.tar.gz: 1c5d04ccce4c26663c820aaa69a06e8eb1de2bd76413541c439974c0b082ab3752441faeead07ac3d1509aba642aa65db616b84f4f18942ffe2d903875f473ec
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2019 JamesJJ
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# duration-human
|
2
|
+
|
3
|
+
Ruby module to entend Numeric class with a method to convert a number of seconds to a human readable time duration.
|
4
|
+
|
5
|
+
For example:
|
6
|
+
|
7
|
+
```
|
8
|
+
80.duration ==> "80 seconds"
|
9
|
+
200.duration ==> "3 minutes and 20 seconds"
|
10
|
+
4800.duration ==> "80 minutes and 0 seconds"
|
11
|
+
9000.duration ==> "2 hours and 30 minutes"
|
12
|
+
93660.duration ==> "26 hours and 1 minutes"
|
13
|
+
349200.duration ==> "4 days and 1 hours"
|
14
|
+
```
|
15
|
+
|
16
|
+
Setting `concise` to `true` in the method arguments will use initials `s`, `m`, `h`, `d` for the units, and omit the word `and`. For example:
|
17
|
+
|
18
|
+
```
|
19
|
+
80.duration(concise: true) ==> "80s"
|
20
|
+
200.duration(concise: true) ==> "3m 20s"
|
21
|
+
93660.duration(concise: true) ==> "26h 1m"
|
22
|
+
349200.duration (concise: true) ==> "4d 1h"
|
23
|
+
```
|
24
|
+
|
25
|
+
The thresholds for chnaging 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".
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "bundler"
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require "rake/testtask"
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs.push("lib", "test")
|
8
|
+
t.test_files = FileList["test/**/test_*.rb"]
|
9
|
+
t.verbose = true
|
10
|
+
t.warning = true
|
11
|
+
end
|
12
|
+
|
13
|
+
task default: [:test]
|
@@ -0,0 +1,27 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "duration-human"
|
6
|
+
spec.version = "0.0.1"
|
7
|
+
spec.authors = ["JamesJJ"]
|
8
|
+
spec.email = ["jj@fcg.fyi"]
|
9
|
+
|
10
|
+
spec.summary = %q{Extend Numeric with method to provide duration as a human readable string}
|
11
|
+
#spec.description = %q{TODO: Write a longer description or delete this line.}
|
12
|
+
spec.homepage = "https://github.com/JamesJJ/ruby-duration-human"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
test_files, files = `git ls-files -z`.split("\x0").partition do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.files = files
|
19
|
+
spec.executables = files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = test_files
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
spec.required_ruby_version = '>= 2.3.0'
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
25
|
+
spec.add_development_dependency "rake", "~> 12.0"
|
26
|
+
spec.add_development_dependency "test-unit", "~> 3.0"
|
27
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class Numeric
|
2
|
+
def duration(concise: false)
|
3
|
+
seconds = self.to_int
|
4
|
+
minutes = seconds / 60
|
5
|
+
hours = minutes / 60
|
6
|
+
days = hours / 24
|
7
|
+
|
8
|
+
if hours >= 48
|
9
|
+
concise ? "#{days}d #{hours % 24}h" : "#{days} days and #{hours % 24} hours"
|
10
|
+
elsif minutes >= 120
|
11
|
+
concise ? "#{hours}h #{minutes % 60}m" : "#{hours} hours and #{minutes % 60} minutes"
|
12
|
+
elsif seconds >= 120
|
13
|
+
concise ? "#{minutes}m #{seconds % 60}s" : "#{minutes} minutes and #{seconds % 60} seconds"
|
14
|
+
elsif seconds >= 0
|
15
|
+
concise ? "#{seconds}s" : "#{seconds} seconds"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
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
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: duration-human
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- JamesJJ
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-05-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '12.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '12.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: test-unit
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- jj@fcg.fyi
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- Gemfile
|
63
|
+
- LICENSE
|
64
|
+
- README.md
|
65
|
+
- Rakefile
|
66
|
+
- duration-human.gemspec
|
67
|
+
- lib/duration-human.rb
|
68
|
+
- test/plugin/test_filter_email_obfuscate.rb
|
69
|
+
- tool/build_and_push_to_rubygems.sh
|
70
|
+
homepage: https://github.com/JamesJJ/ruby-duration-human
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 2.3.0
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.5.2.3
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Extend Numeric with method to provide duration as a human readable string
|
94
|
+
test_files:
|
95
|
+
- test/plugin/test_filter_email_obfuscate.rb
|