Class: HumanDuration
- Inherits:
-
Object
- Object
- HumanDuration
- Defined in:
- lib/human_duration.rb,
lib/human_duration/version.rb
Overview
Doc here
Constant Summary collapse
- VERSION =
'1.0.0'.freeze
Instance Method Summary collapse
- #humanize(seconds) ⇒ Object
-
#initialize(config = { 'type' => 'compact' }) ⇒ HumanDuration
constructor
A new instance of HumanDuration.
Constructor Details
#initialize(config = { 'type' => 'compact' }) ⇒ HumanDuration
Returns a new instance of HumanDuration.
13 14 15 16 17 18 |
# File 'lib/human_duration.rb', line 13 def initialize(config = { 'type' => 'compact' }) @config = config @split_types = [[60, 'second'], [60, 'minute'], [24, 'hour'], [365, 'day'], [1000, 'year']] @short_name_map = { 'second' => 's', 'minute' => 'm', 'hour' => 'h', 'day' => 'd', 'year' => 'y' } end |
Instance Method Details
#humanize(seconds) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/human_duration.rb', line 20 def humanize(seconds) reset return 'negative' if seconds < 0 return 'now' if seconds.zero? split_seconds(seconds) count_items generate_output @output_buffer end |