human_duration 1.0.0 → 1.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 +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +8 -0
- data/README.md +18 -1
- data/example/example.rb +17 -0
- data/human_duration.gemspec +2 -6
- data/lib/human_duration/version.rb +1 -1
- data/lib/human_duration.rb +27 -2
- data/spec/human_duration_spec.rb +104 -0
- metadata +5 -4
- data/Gemfile.lock +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 102134bea90036b011d22347bc8f8470f4b4dd15772fd9b9cde82e99e2592245
|
4
|
+
data.tar.gz: 667534f6929deba4722e44a773f7420ea8eab1b35f02df893cac4b2b7e70952b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d79a19c23c24ae488e85a95a4d25303894e945575173f04fc1d754a5847aea58e96475bd36de0ba629a358367e1308aec8672a514ff17b686e539b3abdd6eda8
|
7
|
+
data.tar.gz: dee5232b143c5a3a6d24a0c764a3d9374e40cd0d1d0433ff88117804bb0e2ae5862f090c345bf02d553ee8c0d05bbc5ade3acd44ae96027a7c5421458c280574
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## 1.0.1 (January 17, 2019)
|
2
|
+
|
3
|
+
CHANGES:
|
4
|
+
|
5
|
+
* Added a new direct access method so that you can call humanize directly. ([@TGWolf][])
|
6
|
+
* Updated the example.rb to show the new method in actions. ([@TGWolf][])
|
7
|
+
* Updated the docs to detail this new access method. ([@TGWolf][])
|
8
|
+
|
1
9
|
## 1.0.0 (January 17, 2019)
|
2
10
|
|
3
11
|
* Initial Release ([@TGWolf][])
|
data/README.md
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
[](https://travis-ci.org/WolfSoftware/human_duration)
|
2
2
|
[](LICENSE.md)
|
3
3
|
[](https://github.com/wolfsoftware/human_duration/releases/latest)
|
4
|
+
[](https://badge.fury.io/rb/human_duration)
|
4
5
|
[](https://github.com/wolfsoftware/human_duration/commits)
|
5
6
|
[](https://github.com/wolfsoftware/human_duration)
|
6
7
|
[](https://github.com/wolfsoftware/human_duration)
|
7
8
|
|
8
9
|
# HumanDuration
|
9
10
|
|
10
|
-
Human Durartion is a simple ruby gem to convert a number of seconds into a more human readable
|
11
|
+
Human Durartion is a simple ruby gem to convert a number of seconds into a more human readable form.
|
11
12
|
|
12
13
|
## Installation
|
13
14
|
|
@@ -27,6 +28,14 @@ Or install it yourself as:
|
|
27
28
|
|
28
29
|
## Usage
|
29
30
|
|
31
|
+
The main function that needs to be called is the 'humanize' function but there are 3 different ways to do this (as show in the code snippet below)
|
32
|
+
|
33
|
+
* Class method access - `hd = HumanDuration.new` followed by `hd.humanize(x)`
|
34
|
+
* Static method access - `HumanDurationStatic.humanize(x)`
|
35
|
+
* Direct method access - `humanize(x)`
|
36
|
+
|
37
|
+
The first method is the main/original method for accessing this function, the other 2 are simple wrappers to the first.
|
38
|
+
|
30
39
|
```ruby
|
31
40
|
#!/usr/bin/env ruby
|
32
41
|
|
@@ -47,6 +56,14 @@ puts 'Config: default'
|
|
47
56
|
test_value.each do |x|
|
48
57
|
puts HumanDurationStatic.humanize(x)
|
49
58
|
end
|
59
|
+
|
60
|
+
puts 'Direct method access'
|
61
|
+
|
62
|
+
puts 'Config: default'
|
63
|
+
test_value.each do |x|
|
64
|
+
puts humanize(x)
|
65
|
+
end
|
66
|
+
|
50
67
|
```
|
51
68
|
|
52
69
|
It is possible to configure the output using one of the options 'compact', 'small' and 'full', 'compact' isthe default. For more detailed example please refer to [example/example.rb](https://github.com/WolfSoftware/human_duration/blob/master/example/example.rb)
|
data/example/example.rb
CHANGED
@@ -39,3 +39,20 @@ puts "\tConfig: type = full"
|
|
39
39
|
test_value.each do |x|
|
40
40
|
printf "\t\t%s\n", HumanDurationStatic.humanize(x)
|
41
41
|
end
|
42
|
+
|
43
|
+
puts 'Direct method access'
|
44
|
+
|
45
|
+
printf "\tConfig: type = conpact [default]\n"
|
46
|
+
test_value.each do |x|
|
47
|
+
printf "\t\t%s\n", humanize(x)
|
48
|
+
end
|
49
|
+
|
50
|
+
printf "\tConfig: type = short\n"
|
51
|
+
test_value.each do |x|
|
52
|
+
printf "\t\t%s\n", humanize(x)
|
53
|
+
end
|
54
|
+
|
55
|
+
puts "\tConfig: type = full"
|
56
|
+
test_value.each do |x|
|
57
|
+
printf "\t\t%s\n", humanize(x)
|
58
|
+
end
|
data/human_duration.gemspec
CHANGED
@@ -8,16 +8,12 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.authors = ["Tim Gurney aka Wolf"]
|
9
9
|
spec.email = ["wolf@tgwolf.com"]
|
10
10
|
|
11
|
-
spec.summary = %q{
|
12
|
-
spec.description = %q{
|
11
|
+
spec.summary = %q{Human Durartion is a simple ruby gem to convert a number of seconds into a more human readable form.}
|
12
|
+
spec.description = %q{Human Durartion is a simple ruby gem to convert a number of seconds into a more human readable form.}
|
13
13
|
spec.homepage = "https://github.com/WolfSoftware/human_duration"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
17
|
-
# spec.files = Dir['lib/**/*.rb']
|
18
|
-
# spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
19
|
-
# f.match(%r{^(test|spec|features)/})
|
20
|
-
# end
|
21
17
|
spec.bindir = "exe"
|
22
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
19
|
spec.require_paths = ["lib"]
|
data/lib/human_duration.rb
CHANGED
@@ -1,6 +1,26 @@
|
|
1
1
|
require 'human_duration/version'
|
2
2
|
|
3
|
-
#
|
3
|
+
# -------------------------------------------------------------------------------- #
|
4
|
+
# Description #
|
5
|
+
# -------------------------------------------------------------------------------- #
|
6
|
+
# Display elapsed time in a more human readable way. #
|
7
|
+
# -------------------------------------------------------------------------------- #
|
8
|
+
|
9
|
+
# -------------------------------------------------------------------------------- #
|
10
|
+
# Description #
|
11
|
+
# -------------------------------------------------------------------------------- #
|
12
|
+
# This is a simple global method to short cut the usage of the class below. #
|
13
|
+
# -------------------------------------------------------------------------------- #
|
14
|
+
def humanize(seconds, config = { 'type' => 'compact' })
|
15
|
+
hd = HumanDuration.new(config)
|
16
|
+
hd.humanize(seconds)
|
17
|
+
end
|
18
|
+
|
19
|
+
# -------------------------------------------------------------------------------- #
|
20
|
+
# Description #
|
21
|
+
# -------------------------------------------------------------------------------- #
|
22
|
+
# This is a static access wrapper to the main HumanDuration class below. #
|
23
|
+
# -------------------------------------------------------------------------------- #
|
4
24
|
class HumanDurationStatic
|
5
25
|
def self.humanize(seconds, config = { 'type' => 'compact' })
|
6
26
|
hd = HumanDuration.new(config)
|
@@ -8,7 +28,12 @@ class HumanDurationStatic
|
|
8
28
|
end
|
9
29
|
end
|
10
30
|
|
11
|
-
#
|
31
|
+
# -------------------------------------------------------------------------------- #
|
32
|
+
# Description #
|
33
|
+
# -------------------------------------------------------------------------------- #
|
34
|
+
# This is the main class and the one that does all the real work and is called by #
|
35
|
+
# the static access class and the direct method access above. #
|
36
|
+
# -------------------------------------------------------------------------------- #
|
12
37
|
class HumanDuration
|
13
38
|
def initialize(config = { 'type' => 'compact' })
|
14
39
|
@config = config
|
data/spec/human_duration_spec.rb
CHANGED
@@ -238,6 +238,110 @@ RSpec.describe HumanDuration do
|
|
238
238
|
end
|
239
239
|
end
|
240
240
|
end
|
241
|
+
|
242
|
+
context 'Direct method access' do
|
243
|
+
context 'Using default compact mode' do
|
244
|
+
it 'says negative for seconds < 0 (Negative value test)' do
|
245
|
+
expect(humanize(-1)).to eql('negative')
|
246
|
+
end
|
247
|
+
|
248
|
+
it 'says now for 0 seconds (Zero second test)' do
|
249
|
+
expect(humanize(0)).to eql('now')
|
250
|
+
end
|
251
|
+
|
252
|
+
it 'says \'1 second\' for 1 second (Singular test)' do
|
253
|
+
expect(humanize(1)).to eql('1 second')
|
254
|
+
end
|
255
|
+
|
256
|
+
it 'says \'10 seconds\' for 10 second (Plural test)' do
|
257
|
+
expect(humanize(10)).to eql('10 seconds')
|
258
|
+
end
|
259
|
+
|
260
|
+
it 'says \'1 minute\' for 60 seconds' do
|
261
|
+
expect(humanize(60)).to eql('1 minute')
|
262
|
+
end
|
263
|
+
|
264
|
+
it 'says \'1 hour\' for 3600 seconds' do
|
265
|
+
expect(humanize(360_0)).to eql('1 hour')
|
266
|
+
end
|
267
|
+
|
268
|
+
it 'says \'1 year\' for 31536000 seconds' do
|
269
|
+
expect(humanize(315_360_00)).to eql('1 year')
|
270
|
+
end
|
271
|
+
|
272
|
+
it 'says \'1 year, 2 hours and 13 seconds\' for 31543213 seconds' do
|
273
|
+
expect(humanize(315_432_13)).to eql('1 year, 2 hours and 13 seconds')
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
context 'Using short mode' do
|
278
|
+
it 'says negative for seconds < 0 (Negative value test)' do
|
279
|
+
expect(humanize(-1, 'type' => 'short')).to eql('negative')
|
280
|
+
end
|
281
|
+
|
282
|
+
it 'says now for 0 seconds (Zero second test)' do
|
283
|
+
expect(humanize(0, 'type' => 'short')).to eql('now')
|
284
|
+
end
|
285
|
+
|
286
|
+
it 'says \'1 s\' for 1 second (Singular test)' do
|
287
|
+
expect(humanize(1, 'type' => 'short')).to eql('1 s')
|
288
|
+
end
|
289
|
+
|
290
|
+
it 'says \'10 s\' for 10 second (Plural test)' do
|
291
|
+
expect(humanize(10, 'type' => 'short')).to eql('10 s')
|
292
|
+
end
|
293
|
+
|
294
|
+
it 'says \'1 m\' for 60 seconds' do
|
295
|
+
expect(humanize(60, 'type' => 'short')).to eql('1 m')
|
296
|
+
end
|
297
|
+
|
298
|
+
it 'says \'1 h\' for 3600 seconds' do
|
299
|
+
expect(humanize(360_0, 'type' => 'short')).to eql('1 h')
|
300
|
+
end
|
301
|
+
|
302
|
+
it 'says \'1 y\' for 31536000 seconds' do
|
303
|
+
expect(humanize(315_360_00, 'type' => 'short')).to eql('1 y')
|
304
|
+
end
|
305
|
+
|
306
|
+
it 'says \'1 y, 2 h & 13 s\' for 31543213 seconds' do
|
307
|
+
expect(humanize(315_432_13, 'type' => 'short')).to eql('1 y, 2 h & 13 s')
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
context 'Using full mode' do
|
312
|
+
it 'says negative for seconds < 0 (Negative value test)' do
|
313
|
+
expect(humanize(-1, 'type' => 'full')).to eql('negative')
|
314
|
+
end
|
315
|
+
|
316
|
+
it 'says now for 0 seconds (Zero second test)' do
|
317
|
+
expect(humanize(0, 'type' => 'full')).to eql('now')
|
318
|
+
end
|
319
|
+
|
320
|
+
it 'says \'0 years, 0 days, 0 hours, 0 minutes and 1 second\' for 1 second (Singular test)' do
|
321
|
+
expect(humanize(1, 'type' => 'full')).to eql('0 years, 0 days, 0 hours, 0 minutes and 1 second')
|
322
|
+
end
|
323
|
+
|
324
|
+
it 'says \'0 years, 0 days, 0 hours, 0 minutes and 10 seconds\' for 10 second (Plural test)' do
|
325
|
+
expect(humanize(10, 'type' => 'full')).to eql('0 years, 0 days, 0 hours, 0 minutes and 10 seconds')
|
326
|
+
end
|
327
|
+
|
328
|
+
it 'says \'0 years, 0 days, 0 hours, 1 minute and 0 seconds\' for 60 seconds' do
|
329
|
+
expect(humanize(60, 'type' => 'full')).to eql('0 years, 0 days, 0 hours, 1 minute and 0 seconds')
|
330
|
+
end
|
331
|
+
|
332
|
+
it 'says \'0 years, 0 days, 1 hour, 0 minutes and 0 seconds\' for 3600 seconds' do
|
333
|
+
expect(humanize(360_0, 'type' => 'full')).to eql('0 years, 0 days, 1 hour, 0 minutes and 0 seconds')
|
334
|
+
end
|
335
|
+
|
336
|
+
it 'says \'1 year, 0 days, 0 hours, 0 minutes and 0 seconds\' for 31536000 seconds' do
|
337
|
+
expect(humanize(315_360_00, 'type' => 'full')).to eql('1 year, 0 days, 0 hours, 0 minutes and 0 seconds')
|
338
|
+
end
|
339
|
+
|
340
|
+
it 'says \'1 year, 0 days, 2 hours, 0 minutes and 13 seconds\' for 31543213 seconds' do
|
341
|
+
expect(humanize(315_432_13, 'type' => 'full')).to eql('1 year, 0 days, 2 hours, 0 minutes and 13 seconds')
|
342
|
+
end
|
343
|
+
end
|
344
|
+
end
|
241
345
|
end
|
242
346
|
|
243
347
|
# rubocop:enable Metrics/BlockLength
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: human_duration
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Gurney aka Wolf
|
@@ -52,7 +52,8 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
-
description:
|
55
|
+
description: Human Durartion is a simple ruby gem to convert a number of seconds into
|
56
|
+
a more human readable form.
|
56
57
|
email:
|
57
58
|
- wolf@tgwolf.com
|
58
59
|
executables: []
|
@@ -67,7 +68,6 @@ files:
|
|
67
68
|
- CODEOWNERS
|
68
69
|
- CODE_OF_CONDUCT.md
|
69
70
|
- Gemfile
|
70
|
-
- Gemfile.lock
|
71
71
|
- LICENSE.txt
|
72
72
|
- README.md
|
73
73
|
- Rakefile
|
@@ -101,5 +101,6 @@ requirements: []
|
|
101
101
|
rubygems_version: 3.0.2
|
102
102
|
signing_key:
|
103
103
|
specification_version: 4
|
104
|
-
summary:
|
104
|
+
summary: Human Durartion is a simple ruby gem to convert a number of seconds into
|
105
|
+
a more human readable form.
|
105
106
|
test_files: []
|
data/Gemfile.lock
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
human_duration (0.1.0)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
diff-lcs (1.3)
|
10
|
-
rake (10.5.0)
|
11
|
-
rspec (3.8.0)
|
12
|
-
rspec-core (~> 3.8.0)
|
13
|
-
rspec-expectations (~> 3.8.0)
|
14
|
-
rspec-mocks (~> 3.8.0)
|
15
|
-
rspec-core (3.8.0)
|
16
|
-
rspec-support (~> 3.8.0)
|
17
|
-
rspec-expectations (3.8.2)
|
18
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
-
rspec-support (~> 3.8.0)
|
20
|
-
rspec-mocks (3.8.0)
|
21
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
-
rspec-support (~> 3.8.0)
|
23
|
-
rspec-support (3.8.0)
|
24
|
-
|
25
|
-
PLATFORMS
|
26
|
-
ruby
|
27
|
-
|
28
|
-
DEPENDENCIES
|
29
|
-
bundler (~> 1.16)
|
30
|
-
human_duration!
|
31
|
-
rake (~> 10.0)
|
32
|
-
rspec (~> 3.0)
|
33
|
-
|
34
|
-
BUNDLED WITH
|
35
|
-
1.16.1
|