tago 0.4.0 → 0.5.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.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +5 -5
  3. data/Rakefile +1 -0
  4. data/lib/tago.rb +23 -20
  5. data/tago.gemspec +1 -1
  6. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6ce49c7e11433395a7963fd3b8ae9a7bfc10dbb00e10fb0a2791b13fb432cf35
4
- data.tar.gz: 861df150e33bcdc48e0d8ec3a34c2a33a5c455be7b19b7b6ebad11e166772b1c
3
+ metadata.gz: 7c58f911880a7e18c878c6d586393e785b4552205d5c9d489dcbf72e7aaab455
4
+ data.tar.gz: de65be56f9a1df5f45343644b50f27496c2daebdb423c4788b085803d8c17bd3
5
5
  SHA512:
6
- metadata.gz: afdfb3de82966a409d8d59498788eaf623d5251f1bd0561e5025662d12a28d705ac96e236014c539fe1e0e4c6270367687d4000f540cd46a5afd1d73c09ddf18
7
- data.tar.gz: ddd745356b376ec6254cf5bfec47b5a388c5d3e595d30ed99d7729bcb91ff678e03a6b3722a891fb569582937b9b0d0078931bde34861efb83dc1f9c5829c2e8
6
+ metadata.gz: c797174c8dc2d002dffc12422f33e70d979fdc73c98150ea52e563cc0581f757444fca01fb492024736bc06c2edce67c6a0db136d57b410322770aae90dae7ff
7
+ data.tar.gz: cd6a4c966a36c85c7e1a8ac0f6cef233070b13e91c60375b543b44a431e55cb466d5d38b680a943a8426e62dae1599f0dd5f50824d847e0ff0237c5244f2d018
data/Gemfile.lock CHANGED
@@ -8,12 +8,12 @@ GEM
8
8
  specs:
9
9
  ast (2.4.3)
10
10
  docile (1.4.1)
11
- json (2.15.1)
11
+ json (2.15.2)
12
12
  language_server-protocol (3.17.0.5)
13
13
  lint_roller (1.1.0)
14
- minitest (5.26.0)
14
+ minitest (5.26.2)
15
15
  parallel (1.27.0)
16
- parser (3.3.9.0)
16
+ parser (3.3.10.0)
17
17
  ast (~> 2.4.1)
18
18
  racc
19
19
  prism (1.5.2)
@@ -22,7 +22,7 @@ GEM
22
22
  rake (13.3.1)
23
23
  regexp_parser (2.11.3)
24
24
  rexml (3.4.2)
25
- rubocop (1.81.6)
25
+ rubocop (1.81.7)
26
26
  json (~> 2.3)
27
27
  language_server-protocol (~> 3.17.0.2)
28
28
  lint_roller (~> 1.1.0)
@@ -60,7 +60,7 @@ GEM
60
60
  unicode-display_width (3.2.0)
61
61
  unicode-emoji (~> 4.1)
62
62
  unicode-emoji (4.1.0)
63
- yard (0.9.37)
63
+ yard (0.9.38)
64
64
 
65
65
  PLATFORMS
66
66
  arm64-darwin-22
data/Rakefile CHANGED
@@ -31,6 +31,7 @@ require 'yard'
31
31
  desc 'Build Yard documentation'
32
32
  YARD::Rake::YardocTask.new do |t|
33
33
  t.files = ['lib/**/*.rb']
34
+ t.options = ['--fail-on-warning']
34
35
  end
35
36
 
36
37
  require 'rubocop/rake_task'
data/lib/tago.rb CHANGED
@@ -11,17 +11,20 @@ require 'time'
11
11
  # Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
12
12
  # License:: MIT
13
13
  class Float
14
- def seconds(format = nil)
14
+ def seconds(*args)
15
15
  s = self
16
16
  s = -s if s.negative?
17
- if format == :pretty
17
+ if args.include?(:pretty)
18
18
  locales = {
19
19
  en: {
20
20
  numbers: { 0 => 'zero', 1 => 'one', 2 => 'two', 3 => 'three', 4 => 'four', 5 => 'five', 6 => 'six',
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] },
25
+ short_units: {
26
+ microsecond: 'μs', millisecond: 'ms', second: 'sec', minute: 'min', hour: 'hr', day: 'd', week: 'wk'
27
+ }
25
28
  }
26
29
  }.freeze
27
30
 
@@ -47,10 +50,12 @@ class Float
47
50
  val = (s / (7 * 24 * 60 * 60)).to_i
48
51
  unit = :week
49
52
  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]
53
+ short = args.include?(:short)
54
+ number_to_words = val <= 10 ? locales[:en][:numbers][val] : val.to_s
55
+ num = short ? val : number_to_words
56
+ names = locales[:en][:units][unit]
57
+ unit_symbol = val == 1 ? names[0] : names[1]
58
+ unit_name = short ? locales[:en][:short_units][unit] : unit_symbol
54
59
  return format('%<num>s %<unit_name>s', num:, unit_name:)
55
60
  end
56
61
 
@@ -60,7 +65,7 @@ class Float
60
65
  format('%dms', s * 1000)
61
66
  elsif s < 10
62
67
  ms = (s * 1000 % 1000).to_i
63
- if format == :round || ms.zero?
68
+ if args.include?(:round) || args.include?(:short) || ms.zero?
64
69
  format('%ds', s)
65
70
  else
66
71
  format('%<s>ds%<ms>dms', s:, ms:)
@@ -70,7 +75,7 @@ class Float
70
75
  elsif s < 60 * 60
71
76
  mins = (s / 60).to_i
72
77
  secs = (s % 60).to_i
73
- if format == :round || secs.zero?
78
+ if args.include?(:round) || args.include?(:short) || secs.zero?
74
79
  format('%dm', mins)
75
80
  else
76
81
  format('%<mins>dm%<secs>ds', mins:, secs:)
@@ -78,7 +83,7 @@ class Float
78
83
  elsif s < 24 * 60 * 60
79
84
  hours = (s / (60 * 60)).to_i
80
85
  mins = ((s % (60 * 60)) / 60).to_i
81
- if format == :round || mins.zero?
86
+ if args.include?(:round) || args.include?(:short) || mins.zero?
82
87
  format('%dh', hours)
83
88
  else
84
89
  format('%<hours>dh%<mins>dm', hours:, mins:)
@@ -86,7 +91,7 @@ class Float
86
91
  elsif s < 7 * 24 * 60 * 60
87
92
  days = (s / (24 * 60 * 60)).to_i
88
93
  hours = ((s % (24 * 60 * 60)) / (60 * 60)).to_i
89
- if format == :round || hours.zero?
94
+ if args.include?(:round) || args.include?(:short) || hours.zero?
90
95
  format('%dd', days)
91
96
  else
92
97
  format('%<days>dd%<hours>dh', days:, hours:)
@@ -94,7 +99,7 @@ class Float
94
99
  else
95
100
  weeks = (s / (7 * 24 * 60 * 60)).to_i
96
101
  days = (s / (24 * 60 * 60) % 7).to_i
97
- if format == :round || days.zero?
102
+ if args.include?(:round) || args.include?(:short) || days.zero?
98
103
  format('%dw', weeks)
99
104
  else
100
105
  format('%<weeks>dw%<days>dd', weeks:, days:)
@@ -109,15 +114,13 @@ end
109
114
  # Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
110
115
  # License:: MIT
111
116
  class Time
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
+ def ago(arg = Time.now, *options)
118
+ if arg.is_a?(Time)
117
119
  now = arg
118
- format = pretty
120
+ else
121
+ now = Time.now
122
+ options = [arg] + options
119
123
  end
120
-
121
- (now - self).seconds(format)
124
+ (now - self).seconds(*options)
122
125
  end
123
126
  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.4.0'
12
+ s.version = '0.5.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.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko