remain_timer 0.2.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8cc9b0db18963128be3fbca5ece763d666e5e8c1a9ec8f31122518bdf8819474
4
- data.tar.gz: 5a9559815a43b8b09d8817a00c161a2dd4b041d9d7cab8166103ca7d0b727f30
3
+ metadata.gz: bf79b68f663dac0480ec619ac7106bc9104cf73abf0a1609c1876d5e4da5e2c5
4
+ data.tar.gz: 3f73f57a2b9c74e7bfdaff55f42c2c48b8faa2c50d439284744777886605ea0e
5
5
  SHA512:
6
- metadata.gz: 171bf41d67020c2fa890b55a12d4ad3734a06dc5f0bb0e7298439ac4d892199ceea61f12f2294f9a5d711f8cc66c19e011e1d5aa629a33c9c0cf1c222701fc5e
7
- data.tar.gz: c9fbb5ed9f89542abe59df6e4c098dac0b70a5c7860c56c3cb5c764d68e116efe604bb1ac79285610000a2da31a4c3746a1c73627505e06e0f8578d8cc4200e0
6
+ metadata.gz: 9754dbda73dceee8b0ab1795d35faf7ce2739eef0127cf8e68d01d8deb70fe8dce3032cb6f4460bad82f7f95e7e3d169d3a99de27e3ceaae9b88b29273589aac
7
+ data.tar.gz: 8156c44039acf3741b542d26d944d5149c166e6af12f3704888fcd10fd39b633e927eff0adc52958529c43459beb667505074bd7becdd310c60062528c64a46d
@@ -0,0 +1,40 @@
1
+ class DurationFormat
2
+ SECONDS_PER_DAY = 86400
3
+ SECONDS_PER_HOUR = 3600
4
+ SECONDS_PER_MINUTE = 60
5
+ PARTS = %i[day hour min sec].freeze
6
+ PARTS_IN_SECONDS = { sec: 1, min: SECONDS_PER_MINUTE, hour: SECONDS_PER_HOUR, day: SECONDS_PER_DAY }.freeze
7
+
8
+ def self.build_parts(value)
9
+ parts = {}
10
+ remainder = value.to_f
11
+
12
+ PARTS.each do |part|
13
+ next if part == :sec
14
+ part_in_seconds = PARTS_IN_SECONDS[part]
15
+ parts[part] = remainder.div(part_in_seconds)
16
+ remainder = (remainder % part_in_seconds).round(9)
17
+ end
18
+
19
+ parts[:sec] = remainder
20
+
21
+ parts
22
+ end
23
+
24
+ def self.format(value)
25
+ parts = build_parts(value)
26
+ (parts[:day] > 0 ? "#{parts[:day]}day " : "") + sprintf('%02d:%02d:%02d', parts[:hour], parts[:min], parts[:sec].round)
27
+ end
28
+ end
29
+
30
+ class Integer
31
+ def duration_format
32
+ DurationFormat.format(self)
33
+ end
34
+ end
35
+
36
+ class Float
37
+ def duration_format
38
+ DurationFormat.format(self)
39
+ end
40
+ end
@@ -1,3 +1,3 @@
1
1
  class RemainTimer
2
- VERSION = "0.2.0".freeze
2
+ VERSION = "0.2.1".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remain_timer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Narazaka
@@ -29,6 +29,7 @@ files:
29
29
  - Rakefile
30
30
  - bin/console
31
31
  - bin/setup
32
+ - lib/duration_format.rb
32
33
  - lib/remain_timer.rb
33
34
  - lib/remain_timer/version.rb
34
35
  - remain_timer.gemspec