tago 0.3.0 → 0.4.0
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/Gemfile.lock +13 -13
- data/lib/tago.rb +50 -2
- data/tago.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6ce49c7e11433395a7963fd3b8ae9a7bfc10dbb00e10fb0a2791b13fb432cf35
|
|
4
|
+
data.tar.gz: 861df150e33bcdc48e0d8ec3a34c2a33a5c455be7b19b7b6ebad11e166772b1c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: afdfb3de82966a409d8d59498788eaf623d5251f1bd0561e5025662d12a28d705ac96e236014c539fe1e0e4c6270367687d4000f540cd46a5afd1d73c09ddf18
|
|
7
|
+
data.tar.gz: ddd745356b376ec6254cf5bfec47b5a388c5d3e595d30ed99d7729bcb91ff678e03a6b3722a891fb569582937b9b0d0078931bde34861efb83dc1f9c5829c2e8
|
data/Gemfile.lock
CHANGED
|
@@ -8,21 +8,21 @@ GEM
|
|
|
8
8
|
specs:
|
|
9
9
|
ast (2.4.3)
|
|
10
10
|
docile (1.4.1)
|
|
11
|
-
json (2.
|
|
11
|
+
json (2.15.1)
|
|
12
12
|
language_server-protocol (3.17.0.5)
|
|
13
13
|
lint_roller (1.1.0)
|
|
14
|
-
minitest (5.
|
|
14
|
+
minitest (5.26.0)
|
|
15
15
|
parallel (1.27.0)
|
|
16
16
|
parser (3.3.9.0)
|
|
17
17
|
ast (~> 2.4.1)
|
|
18
18
|
racc
|
|
19
|
-
prism (1.
|
|
19
|
+
prism (1.5.2)
|
|
20
20
|
racc (1.8.1)
|
|
21
21
|
rainbow (3.1.1)
|
|
22
|
-
rake (13.3.
|
|
23
|
-
regexp_parser (2.11.
|
|
22
|
+
rake (13.3.1)
|
|
23
|
+
regexp_parser (2.11.3)
|
|
24
24
|
rexml (3.4.2)
|
|
25
|
-
rubocop (1.
|
|
25
|
+
rubocop (1.81.6)
|
|
26
26
|
json (~> 2.3)
|
|
27
27
|
language_server-protocol (~> 3.17.0.2)
|
|
28
28
|
lint_roller (~> 1.1.0)
|
|
@@ -30,20 +30,20 @@ GEM
|
|
|
30
30
|
parser (>= 3.3.0.2)
|
|
31
31
|
rainbow (>= 2.2.2, < 4.0)
|
|
32
32
|
regexp_parser (>= 2.9.3, < 3.0)
|
|
33
|
-
rubocop-ast (>= 1.
|
|
33
|
+
rubocop-ast (>= 1.47.1, < 2.0)
|
|
34
34
|
ruby-progressbar (~> 1.7)
|
|
35
35
|
unicode-display_width (>= 2.4.0, < 4.0)
|
|
36
|
-
rubocop-ast (1.
|
|
36
|
+
rubocop-ast (1.47.1)
|
|
37
37
|
parser (>= 3.3.7.2)
|
|
38
38
|
prism (~> 1.4)
|
|
39
39
|
rubocop-minitest (0.38.2)
|
|
40
40
|
lint_roller (~> 1.1)
|
|
41
41
|
rubocop (>= 1.75.0, < 2.0)
|
|
42
42
|
rubocop-ast (>= 1.38.0, < 2.0)
|
|
43
|
-
rubocop-performance (1.26.
|
|
43
|
+
rubocop-performance (1.26.1)
|
|
44
44
|
lint_roller (~> 1.1)
|
|
45
45
|
rubocop (>= 1.75.0, < 2.0)
|
|
46
|
-
rubocop-ast (>= 1.
|
|
46
|
+
rubocop-ast (>= 1.47.1, < 2.0)
|
|
47
47
|
rubocop-rake (0.7.1)
|
|
48
48
|
lint_roller (~> 1.1)
|
|
49
49
|
rubocop (>= 1.72.1)
|
|
@@ -57,9 +57,9 @@ GEM
|
|
|
57
57
|
simplecov (~> 0.19)
|
|
58
58
|
simplecov-html (0.13.2)
|
|
59
59
|
simplecov_json_formatter (0.1.4)
|
|
60
|
-
unicode-display_width (3.
|
|
61
|
-
unicode-emoji (~> 4.
|
|
62
|
-
unicode-emoji (4.0
|
|
60
|
+
unicode-display_width (3.2.0)
|
|
61
|
+
unicode-emoji (~> 4.1)
|
|
62
|
+
unicode-emoji (4.1.0)
|
|
63
63
|
yard (0.9.37)
|
|
64
64
|
|
|
65
65
|
PLATFORMS
|
data/lib/tago.rb
CHANGED
|
@@ -14,6 +14,46 @@ class Float
|
|
|
14
14
|
def seconds(format = nil)
|
|
15
15
|
s = self
|
|
16
16
|
s = -s if s.negative?
|
|
17
|
+
if format == :pretty
|
|
18
|
+
locales = {
|
|
19
|
+
en: {
|
|
20
|
+
numbers: { 0 => 'zero', 1 => 'one', 2 => 'two', 3 => 'three', 4 => 'four', 5 => 'five', 6 => 'six',
|
|
21
|
+
7 => 'seven', 8 => 'eight', 9 => 'nine', 10 => 'ten' },
|
|
22
|
+
units: { microsecond: %w[microsecond microseconds], millisecond: %w[millisecond milliseconds],
|
|
23
|
+
second: %w[second seconds], minute: %w[minute minutes], hour: %w[hour hours], day: %w[day days],
|
|
24
|
+
week: %w[week weeks] }
|
|
25
|
+
}
|
|
26
|
+
}.freeze
|
|
27
|
+
|
|
28
|
+
if s < 0.001
|
|
29
|
+
val = (s * 1_000_000).to_i
|
|
30
|
+
unit = :microsecond
|
|
31
|
+
elsif s < 1
|
|
32
|
+
val = (s * 1000).to_i
|
|
33
|
+
unit = :millisecond
|
|
34
|
+
elsif s < 60
|
|
35
|
+
val = s.to_i
|
|
36
|
+
unit = :second
|
|
37
|
+
elsif s < 60 * 60
|
|
38
|
+
val = (s / 60).to_i
|
|
39
|
+
unit = :minute
|
|
40
|
+
elsif s < 24 * 60 * 60
|
|
41
|
+
val = (s / (60 * 60)).to_i
|
|
42
|
+
unit = :hour
|
|
43
|
+
elsif s < 7 * 24 * 60 * 60
|
|
44
|
+
val = (s / (24 * 60 * 60)).to_i
|
|
45
|
+
unit = :day
|
|
46
|
+
else
|
|
47
|
+
val = (s / (7 * 24 * 60 * 60)).to_i
|
|
48
|
+
unit = :week
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
num = val < 10 ? locales[:en][:numbers][val] : val.to_s
|
|
52
|
+
names = locales[:en][:units].fetch(unit)
|
|
53
|
+
unit_name = val == 1 ? names[0] : names[1]
|
|
54
|
+
return format('%<num>s %<unit_name>s', num:, unit_name:)
|
|
55
|
+
end
|
|
56
|
+
|
|
17
57
|
if s < 0.001
|
|
18
58
|
format('%dμs', s * 1000 * 1000)
|
|
19
59
|
elsif s < 1
|
|
@@ -69,7 +109,15 @@ end
|
|
|
69
109
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
70
110
|
# License:: MIT
|
|
71
111
|
class Time
|
|
72
|
-
def ago(
|
|
73
|
-
(
|
|
112
|
+
def ago(arg = Time.now, pretty = nil)
|
|
113
|
+
if arg.is_a?(Symbol) || arg.nil?
|
|
114
|
+
format = arg
|
|
115
|
+
now = pretty || Time.now
|
|
116
|
+
else
|
|
117
|
+
now = arg
|
|
118
|
+
format = pretty
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
(now - self).seconds(format)
|
|
74
122
|
end
|
|
75
123
|
end
|
data/tago.gemspec
CHANGED
|
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|
|
9
9
|
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
|
|
10
10
|
s.required_ruby_version = '>=3.0'
|
|
11
11
|
s.name = 'tago'
|
|
12
|
-
s.version = '0.
|
|
12
|
+
s.version = '0.4.0'
|
|
13
13
|
s.license = 'MIT'
|
|
14
14
|
s.summary = 'A new .ago() method for the Time class'
|
|
15
15
|
s.description =
|