Class: Numeric
- Inherits:
-
Object
- Object
- Numeric
- Defined in:
- lib/doing/numeric_chronify.rb
Overview
Number helpers
Instance Method Summary collapse
-
#format_time(human: false) ⇒ Object
Format human readable time from seconds.
-
#time_string(format: :dhm) ⇒ Object
Format seconds as natural language time string.
Instance Method Details
#format_time(human: false) ⇒ Object
Format human readable time from seconds
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/doing/numeric_chronify.rb', line 13 def format_time(human: false) return [0, 0, 0] if nil? seconds = dup.to_i minutes = (seconds / 60).to_i hours = (minutes / 60).to_i if human minutes = (minutes % 60).to_i [0, hours, minutes] else days = (hours / 24).to_i hours = (hours % 24).to_i minutes = (minutes % 60).to_i [days, hours, minutes] end end |
#time_string(format: :dhm) ⇒ Object
Format seconds as natural language time string
36 37 38 |
# File 'lib/doing/numeric_chronify.rb', line 36 def time_string(format: :dhm) format_time(human: true).time_string(format: format) end |