tago 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: edc7f306a06b74be8335840e6389c78fb14e717e3e14600def550c2a1635835e
4
- data.tar.gz: 955a080225f4377310a2f9aca051e9d8af109653be32c13ed0e03d89ed61ff5e
3
+ metadata.gz: 0127fd10025c451f556575af7705a2956defe95bca254d3c6e15fd340b23c0b1
4
+ data.tar.gz: 00e85043722bb7b4a1303954ecd6df39f8b3bd001090cfe61d14235b3b0bfdd3
5
5
  SHA512:
6
- metadata.gz: 2a57f8321378010be1e3a04613b95a98b5e1988ccbe164cd0d261ca409d5d9837059289fb4c7adde269b33ff10ec819d4fead20a49cd9e3827ff280e66e068a7
7
- data.tar.gz: 2fa126ecd1d8f59fecfdddff57e5003ecb74dd2e2c8c91cc314f3e72a750a15e48a9c2770d258f23f70d902a2c8d6a42401be50d790a19bed0b1f2b9069f9577
6
+ metadata.gz: ec9090a17889ec2cb4ebbf66323ccf678bcd668c82320731bf1c00f23a1fb5d348f76c50f16d03ff0967ae8ffae99340b1ed6f9ce08e7488914a0b6ef5647552
7
+ data.tar.gz: c84b2694de35f985e1150d5464c186ac61c3b6155ff2ba0a7e97a72cbab5945dffdb2d8363ca992d423c96308756fba7964454516afa7125e052d1b81e4b709e
data/Gemfile CHANGED
@@ -26,7 +26,7 @@ gemspec
26
26
  gem 'minitest', '5.23.1', require: false
27
27
  gem 'rake', '13.2.1', require: false
28
28
  gem 'rubocop', '1.64.1', require: false
29
- gem 'rubocop-rspec', '2.31.0', require: false
29
+ gem 'rubocop-rspec', '3.0.1', require: false
30
30
  gem 'simplecov', '0.22.0', require: false
31
31
  gem 'simplecov-cobertura', '2.1.0', require: false
32
32
  gem 'yard', '0.9.36', require: false
data/Gemfile.lock CHANGED
@@ -34,17 +34,8 @@ GEM
34
34
  unicode-display_width (>= 2.4.0, < 3.0)
35
35
  rubocop-ast (1.31.3)
36
36
  parser (>= 3.3.1.0)
37
- rubocop-capybara (2.21.0)
38
- rubocop (~> 1.41)
39
- rubocop-factory_bot (2.26.0)
40
- rubocop (~> 1.41)
41
- rubocop-rspec (2.31.0)
42
- rubocop (~> 1.40)
43
- rubocop-capybara (~> 2.17)
44
- rubocop-factory_bot (~> 2.22)
45
- rubocop-rspec_rails (~> 2.28)
46
- rubocop-rspec_rails (2.29.0)
47
- rubocop (~> 1.40)
37
+ rubocop-rspec (3.0.1)
38
+ rubocop (~> 1.61)
48
39
  ruby-progressbar (1.13.0)
49
40
  simplecov (0.22.0)
50
41
  docile (~> 1.1)
@@ -69,7 +60,7 @@ DEPENDENCIES
69
60
  minitest (= 5.23.1)
70
61
  rake (= 13.2.1)
71
62
  rubocop (= 1.64.1)
72
- rubocop-rspec (= 2.31.0)
63
+ rubocop-rspec (= 3.0.1)
73
64
  simplecov (= 0.22.0)
74
65
  simplecov-cobertura (= 2.1.0)
75
66
  tago!
data/lib/tago.rb CHANGED
@@ -35,16 +35,23 @@ class Time
35
35
  format('%dμs', s * 1000 * 1000)
36
36
  elsif s < 1
37
37
  format('%dms', s * 1000)
38
- elsif s < 60
39
- format('%.1fs', s)
38
+ elsif s < 10
39
+ ms = format('%03d', s * 1000 % 1000)
40
+ if ms == '000'
41
+ format('%ds', s)
42
+ else
43
+ format('%<sec>ds%<msec>sms', sec: s, msec: ms)
44
+ end
45
+ elsif s < 100
46
+ format('%ds', s)
40
47
  elsif s < 60 * 60
41
- format('%.1fm', s / 60)
48
+ format('%<mins>dm%<secs>ds', mins: s / 60, secs: s % 60)
42
49
  elsif s < 24 * 60 * 60
43
- format('%.1fh', s / (60 * 60))
50
+ format('%<hours>dh%<mins>dm', hours: s / (60 * 60), mins: (s % (60 * 60)) / 60)
44
51
  elsif s < 7 * 24 * 60 * 60
45
- format('%.1fd', s / (24 * 60 * 60))
52
+ format('%<days>dd%<hours>dh', days: s / (24 * 60 * 60), hours: (s % (24 * 60 * 60)) / (60 * 60))
46
53
  else
47
- format('%.1fw', s / (7 * 24 * 60 * 60))
54
+ format('%<weeks>dw%<days>dd', weeks: s / (7 * 24 * 60 * 60), days: s % (7 * 24 * 60 * 60) / (24 * 60 * 60))
48
55
  end
49
56
  end
50
57
  end
data/tago.gemspec CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |s|
27
27
  s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
28
28
  s.required_ruby_version = '>=3.0'
29
29
  s.name = 'tago'
30
- s.version = '0.0.1'
30
+ s.version = '0.0.2'
31
31
  s.license = 'MIT'
32
32
  s.summary = 'A new .ago() method for the Time class'
33
33
  s.description =
data/test/test_tago.rb CHANGED
@@ -31,20 +31,23 @@ class TestTago < Minitest::Test
31
31
  def test_simple_printing
32
32
  t = Time.now
33
33
  assert_equal('14ms', (t - 0.014).ago(t))
34
- assert_equal('1.0s', (t - 1).ago(t))
35
- assert_equal('1.1m', (t - 67).ago(t))
36
- assert_equal('13.0h', (t - (13 * 60 * 60)).ago(t))
37
- assert_equal('5.0d', (t - (5 * 24 * 60 * 60)).ago(t))
38
- assert_equal('22.1w', (t - (155 * 24 * 60 * 60)).ago(t))
34
+ assert_equal('1s', (t - 1).ago(t))
35
+ assert_equal('1s350ms', (t - 1.35).ago(t))
36
+ assert_equal('67s', (t - 67).ago(t))
37
+ assert_equal('4m5s', (t - 245).ago(t))
38
+ assert_equal('13h18m', (t - (13.3 * 60 * 60)).ago(t))
39
+ assert_equal('5d0h', (t - (5 * 24 * 60 * 60)).ago(t))
40
+ assert_equal('5d7h', (t - (5.3 * 24 * 60 * 60)).ago(t))
41
+ assert_equal('22w1d', (t - (155 * 24 * 60 * 60)).ago(t))
39
42
  end
40
43
 
41
44
  def test_inverse
42
45
  t = Time.now
43
46
  assert_equal('14ms', (t + 0.014).ago(t))
44
- assert_equal('1.0s', (t + 1).ago(t))
45
- assert_equal('1.1m', (t + 67).ago(t))
46
- assert_equal('13.0h', (t + (13 * 60 * 60)).ago(t))
47
- assert_equal('5.0d', (t + (5 * 24 * 60 * 60)).ago(t))
48
- assert_equal('22.1w', (t + (155 * 24 * 60 * 60)).ago(t))
47
+ assert_equal('1s', (t + 1).ago(t))
48
+ assert_equal('67s', (t + 67).ago(t))
49
+ assert_equal('13h0m', (t + (13 * 60 * 60)).ago(t))
50
+ assert_equal('5d0h', (t + (5 * 24 * 60 * 60)).ago(t))
51
+ assert_equal('22w1d', (t + (155 * 24 * 60 * 60)).ago(t))
49
52
  end
50
53
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tago
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-11 00:00:00.000000000 Z
11
+ date: 2024-06-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: This simple gem adds a new supplementary method .ago() to the existing
14
14
  class Time, thus making logging more convenient