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 +4 -4
- data/lib/duration_format.rb +40 -0
- data/lib/remain_timer/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf79b68f663dac0480ec619ac7106bc9104cf73abf0a1609c1876d5e4da5e2c5
|
4
|
+
data.tar.gz: 3f73f57a2b9c74e7bfdaff55f42c2c48b8faa2c50d439284744777886605ea0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/remain_timer/version.rb
CHANGED
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.
|
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
|