tago 0.5.0 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7c58f911880a7e18c878c6d586393e785b4552205d5c9d489dcbf72e7aaab455
4
- data.tar.gz: de65be56f9a1df5f45343644b50f27496c2daebdb423c4788b085803d8c17bd3
3
+ metadata.gz: b4e8598879603e55acc0cda3df629ded3ff88855eb9233895beddcefec279c87
4
+ data.tar.gz: 4a14e46f54c5c1dae2233bcb71876610946a10b480c1ca454b65c4a127edaba0
5
5
  SHA512:
6
- metadata.gz: c797174c8dc2d002dffc12422f33e70d979fdc73c98150ea52e563cc0581f757444fca01fb492024736bc06c2edce67c6a0db136d57b410322770aae90dae7ff
7
- data.tar.gz: cd6a4c966a36c85c7e1a8ac0f6cef233070b13e91c60375b543b44a431e55cb466d5d38b680a943a8426e62dae1599f0dd5f50824d847e0ff0237c5244f2d018
6
+ metadata.gz: ebee72e43d01da91d5ac3010c990eabd53c3f904ff6a57c541176fb2bf5f314e8327bc96a7fb5e001a4357391f85a48ee5f7d6135fff03bd06179573063c9a05
7
+ data.tar.gz: ad26ded7b5ebd39f523bb8a447659df74f4f16588376daae0b418ac4c79ec2402d5fafa0da24df849709217870a2961f9f0c0c1ad8e4ca3aba5b7ceb43303eb6
data/Gemfile CHANGED
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
3
+ # SPDX-FileCopyrightText: Copyright (c) 2024-2026 Yegor Bugayenko
4
4
  # SPDX-License-Identifier: MIT
5
5
 
6
6
  source 'https://rubygems.org'
7
7
  gemspec
8
8
 
9
- gem 'minitest', '~>5.24', require: false
9
+ gem 'minitest', '~>6.0', require: false
10
10
  gem 'rake', '~>13.2', require: false
11
11
  gem 'rubocop', '~>1.75', require: false
12
12
  gem 'rubocop-minitest', '~>0.38', require: false
data/Gemfile.lock CHANGED
@@ -8,21 +8,22 @@ GEM
8
8
  specs:
9
9
  ast (2.4.3)
10
10
  docile (1.4.1)
11
- json (2.15.2)
11
+ json (2.18.0)
12
12
  language_server-protocol (3.17.0.5)
13
13
  lint_roller (1.1.0)
14
- minitest (5.26.2)
14
+ minitest (6.0.1)
15
+ prism (~> 1.5)
15
16
  parallel (1.27.0)
16
17
  parser (3.3.10.0)
17
18
  ast (~> 2.4.1)
18
19
  racc
19
- prism (1.5.2)
20
+ prism (1.6.0)
20
21
  racc (1.8.1)
21
22
  rainbow (3.1.1)
22
23
  rake (13.3.1)
23
24
  regexp_parser (2.11.3)
24
25
  rexml (3.4.2)
25
- rubocop (1.81.7)
26
+ rubocop (1.82.1)
26
27
  json (~> 2.3)
27
28
  language_server-protocol (~> 3.17.0.2)
28
29
  lint_roller (~> 1.1.0)
@@ -30,10 +31,10 @@ GEM
30
31
  parser (>= 3.3.0.2)
31
32
  rainbow (>= 2.2.2, < 4.0)
32
33
  regexp_parser (>= 2.9.3, < 3.0)
33
- rubocop-ast (>= 1.47.1, < 2.0)
34
+ rubocop-ast (>= 1.48.0, < 2.0)
34
35
  ruby-progressbar (~> 1.7)
35
36
  unicode-display_width (>= 2.4.0, < 4.0)
36
- rubocop-ast (1.47.1)
37
+ rubocop-ast (1.48.0)
37
38
  parser (>= 3.3.7.2)
38
39
  prism (~> 1.4)
39
40
  rubocop-minitest (0.38.2)
@@ -71,7 +72,7 @@ PLATFORMS
71
72
  x86_64-linux
72
73
 
73
74
  DEPENDENCIES
74
- minitest (~> 5.24)
75
+ minitest (~> 6.0)
75
76
  rake (~> 13.2)
76
77
  rubocop (~> 1.75)
77
78
  rubocop-minitest (~> 0.38)
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2024-2025 Yegor Bugayenko
3
+ Copyright (c) 2024-2026 Yegor Bugayenko
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the 'Software'), to deal
data/LICENSES/MIT.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2024-2025 Yegor Bugayenko
3
+ Copyright (c) 2024-2026 Yegor Bugayenko
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the 'Software'), to deal
data/README.md CHANGED
@@ -32,6 +32,27 @@ s = Time.now - start
32
32
  puts "It took #{s.seconds}"
33
33
  ```
34
34
 
35
+ The `seconds` method accepts optional formatting flags:
36
+
37
+ ```ruby
38
+ 9.444.seconds # => "9s444ms"
39
+ 9.444.seconds(:round) # => "9s" (omits sub-units)
40
+ 9.444.seconds(:short) # => "9s" (also omits sub-units)
41
+ 300.0.seconds(:pretty) # => "five minutes" (words instead of abbreviations)
42
+ 300.0.seconds(:pretty, :short) # => "5 min" (numeric with short unit names)
43
+ 5.0.seconds(:pretty, :caps) # => "Five seconds" (capitalizes first letter)
44
+ ```
45
+
46
+ The same flags work with `ago`:
47
+
48
+ ```ruby
49
+ start.ago(:round)
50
+ start.ago(:pretty)
51
+ start.ago(:pretty, :short)
52
+ start.ago(:pretty, :caps)
53
+ start.ago(Time.now, :round)
54
+ ```
55
+
35
56
  The gem basically extends the `Float` and `Time` classes with new methods.
36
57
 
37
58
  ## How to contribute
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
3
+ # SPDX-FileCopyrightText: Copyright (c) 2024-2026 Yegor Bugayenko
4
4
  # SPDX-License-Identifier: MIT
5
5
 
6
6
  require 'rubygems'
data/lib/tago.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
3
+ # SPDX-FileCopyrightText: Copyright (c) 2024-2026 Yegor Bugayenko
4
4
  # SPDX-License-Identifier: MIT
5
5
 
6
6
  require 'time'
@@ -8,7 +8,7 @@ require 'time'
8
8
  # A new method to print time as text.
9
9
  #
10
10
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
11
- # Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
11
+ # Copyright:: Copyright (c) 2024-2026 Yegor Bugayenko
12
12
  # License:: MIT
13
13
  class Float
14
14
  def seconds(*args)
@@ -21,9 +21,10 @@ class Float
21
21
  7 => 'seven', 8 => 'eight', 9 => 'nine', 10 => 'ten' },
22
22
  units: { microsecond: %w[microsecond microseconds], millisecond: %w[millisecond milliseconds],
23
23
  second: %w[second seconds], minute: %w[minute minutes], hour: %w[hour hours], day: %w[day days],
24
- week: %w[week weeks] },
24
+ week: %w[week weeks], month: %w[month months], year: %w[year years] },
25
25
  short_units: {
26
- microsecond: 'μs', millisecond: 'ms', second: 'sec', minute: 'min', hour: 'hr', day: 'd', week: 'wk'
26
+ microsecond: 'μs', millisecond: 'ms', second: 'sec', minute: 'min', hour: 'hr', day: 'd', week: 'wk',
27
+ month: 'mo', year: 'y'
27
28
  }
28
29
  }
29
30
  }.freeze
@@ -46,9 +47,15 @@ class Float
46
47
  elsif s < 7 * 24 * 60 * 60
47
48
  val = (s / (24 * 60 * 60)).to_i
48
49
  unit = :day
49
- else
50
+ elsif s < 30 * 24 * 60 * 60
50
51
  val = (s / (7 * 24 * 60 * 60)).to_i
51
52
  unit = :week
53
+ elsif s < 365 * 24 * 60 * 60
54
+ val = (s / (30 * 24 * 60 * 60)).to_i
55
+ unit = :month
56
+ else
57
+ val = (s / (365 * 24 * 60 * 60)).to_i
58
+ unit = :year
52
59
  end
53
60
  short = args.include?(:short)
54
61
  number_to_words = val <= 10 ? locales[:en][:numbers][val] : val.to_s
@@ -56,7 +63,8 @@ class Float
56
63
  names = locales[:en][:units][unit]
57
64
  unit_symbol = val == 1 ? names[0] : names[1]
58
65
  unit_name = short ? locales[:en][:short_units][unit] : unit_symbol
59
- return format('%<num>s %<unit_name>s', num:, unit_name:)
66
+ result = format('%<num>s %<unit_name>s', num:, unit_name:)
67
+ return args.include?(:caps) ? result.capitalize : result
60
68
  end
61
69
 
62
70
  if s < 0.001
@@ -96,7 +104,7 @@ class Float
96
104
  else
97
105
  format('%<days>dd%<hours>dh', days:, hours:)
98
106
  end
99
- else
107
+ elsif s < 30 * 24 * 60 * 60
100
108
  weeks = (s / (7 * 24 * 60 * 60)).to_i
101
109
  days = (s / (24 * 60 * 60) % 7).to_i
102
110
  if args.include?(:round) || args.include?(:short) || days.zero?
@@ -104,6 +112,22 @@ class Float
104
112
  else
105
113
  format('%<weeks>dw%<days>dd', weeks:, days:)
106
114
  end
115
+ elsif s < 365 * 24 * 60 * 60
116
+ months = (s / (30 * 24 * 60 * 60)).to_i
117
+ weeks = ((s % (30 * 24 * 60 * 60)) / (7 * 24 * 60 * 60)).to_i
118
+ if args.include?(:round) || args.include?(:short) || weeks.zero?
119
+ format('%dmo', months)
120
+ else
121
+ format('%<months>dmo%<weeks>dw', months:, weeks:)
122
+ end
123
+ else
124
+ years = (s / (365 * 24 * 60 * 60)).to_i
125
+ months = ((s % (365 * 24 * 60 * 60)) / (30 * 24 * 60 * 60)).to_i
126
+ if args.include?(:round) || args.include?(:short) || months.zero?
127
+ format('%dy', years)
128
+ else
129
+ format('%<years>dy%<months>dmo', years:, months:)
130
+ end
107
131
  end
108
132
  end
109
133
  end
@@ -111,7 +135,7 @@ end
111
135
  # A new method to print time as text.
112
136
  #
113
137
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
114
- # Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
138
+ # Copyright:: Copyright (c) 2024-2026 Yegor Bugayenko
115
139
  # License:: MIT
116
140
  class Time
117
141
  def ago(arg = Time.now, *options)
data/tago.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
3
+ # SPDX-FileCopyrightText: Copyright (c) 2024-2026 Yegor Bugayenko
4
4
  # SPDX-License-Identifier: MIT
5
5
 
6
6
  require 'English'
@@ -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.5.0'
12
+ s.version = '0.7.0'
13
13
  s.license = 'MIT'
14
14
  s.summary = 'A new .ago() method for the Time class'
15
15
  s.description =
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tago
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko