Class: Timerizer::Duration::RoundedTime
- Inherits:
-
Object
- Object
- Timerizer::Duration::RoundedTime
- Extended by:
- Forwardable
- Defined in:
- lib/timerizer/duration/rounded_time.rb
Overview
Wraps rounding a Timerizer::Duration to the nearest value by the number of “places”, which are customary time units (seconds, minutes, hours, days, months, years, etc; decades and weeks are not included).
Constant Summary collapse
- DEFAULT_PLACES =
Default “places” (units, e.g., hours/minutes) to use for rounding.
2
- OMITTED_KEYS =
Default UNITS not to include in rounded value.
[:decades, :weeks]
Class Method Summary collapse
-
.call(duration, places = DEFAULT_PLACES, omitted_keys = OMITTED_KEYS) ⇒ Timerizer::Duration
Given an original Timerizer::Duration instance, return a new instance that “rounds” the duration to the closest value expressed in a certain number of units (default 2).
Instance Method Summary collapse
-
#call ⇒ Timerizer::Duration
High-level method to do calculations on component durations.
- #remainder_times ⇒ Object
- #target_unit ⇒ Object
- #times ⇒ Object
Class Method Details
.call(duration, places = DEFAULT_PLACES, omitted_keys = OMITTED_KEYS) ⇒ Timerizer::Duration
Given an original Timerizer::Duration instance, return a new instance that “rounds” the duration to the closest value expressed in a certain number of units (default 2).
46 47 48 49 |
# File 'lib/timerizer/duration/rounded_time.rb', line 46 def self.call(duration, places = DEFAULT_PLACES, omitted_keys = OMITTED_KEYS) new(duration, places, omitted_keys).call end |
Instance Method Details
#call ⇒ Timerizer::Duration
High-level method to do calculations on component durations.
55 56 57 58 |
# File 'lib/timerizer/duration/rounded_time.rb', line 55 def call remainder = sum_of(remainder_times) sum_of(times) + offset_from(remainder) end |
#remainder_times ⇒ Object
20 |
# File 'lib/timerizer/duration/rounded_time.rb', line 20 def_delegators :@tt, :remainder_times, :target_unit, :times |
#target_unit ⇒ Object
20 |
# File 'lib/timerizer/duration/rounded_time.rb', line 20 def_delegators :@tt, :remainder_times, :target_unit, :times |
#times ⇒ Object
20 |
# File 'lib/timerizer/duration/rounded_time.rb', line 20 def_delegators :@tt, :remainder_times, :target_unit, :times |