lib/duration_format.rb in remain_timer-0.2.1 vs lib/duration_format.rb in remain_timer-0.2.2
- old
+ new
@@ -1,11 +1,16 @@
class DurationFormat
SECONDS_PER_DAY = 86400
SECONDS_PER_HOUR = 3600
SECONDS_PER_MINUTE = 60
PARTS = %i[day hour min sec].freeze
- PARTS_IN_SECONDS = { sec: 1, min: SECONDS_PER_MINUTE, hour: SECONDS_PER_HOUR, day: SECONDS_PER_DAY }.freeze
+ PARTS_IN_SECONDS = {
+ sec: 1,
+ min: SECONDS_PER_MINUTE,
+ hour: SECONDS_PER_HOUR,
+ day: SECONDS_PER_DAY,
+ }.freeze
def self.build_parts(value)
parts = {}
remainder = value.to_f
@@ -21,20 +26,9 @@
parts
end
def self.format(value)
parts = build_parts(value)
- (parts[:day] > 0 ? "#{parts[:day]}day " : "") + sprintf('%02d:%02d:%02d', parts[:hour], parts[:min], parts[:sec].round)
- end
-end
-
-class Integer
- def duration_format
- DurationFormat.format(self)
- end
-end
-
-class Float
- def duration_format
- DurationFormat.format(self)
+ (parts[:day] > 0 ? "#{parts[:day]}day " : "") +
+ sprintf('%02d:%02d:%02d', parts[:hour], parts[:min], parts[:sec].round)
end
end