Class: Runby::PaceRange
- Inherits:
-
RunbyRange
- Object
- RunbyRange
- Runby::PaceRange
- Defined in:
- lib/runby_pace/pace_range.rb
Overview
Represents a range of paces, from fast to slow.
Instance Attribute Summary
Attributes inherited from RunbyRange
Instance Method Summary collapse
- #as_speed_range ⇒ Object
-
#initialize(fast, slow, distance_units = :km) ⇒ PaceRange
constructor
A new instance of PaceRange.
- #to_s(format: :short) ⇒ Object
Constructor Details
#initialize(fast, slow, distance_units = :km) ⇒ PaceRange
Returns a new instance of PaceRange.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/runby_pace/pace_range.rb', line 8 def initialize(fast, slow, distance_units = :km) if fast.is_a?(Pace) && slow.is_a?(Pace) @fast = fast @slow = slow else # Hopefully 'fast' and 'slow' are parseable as a RunbyTime distance = Distance.new distance_units, 1 @fast = Pace.new(fast, distance) @slow = Pace.new(slow, distance) end freeze end |
Instance Method Details
#as_speed_range ⇒ Object
21 22 23 |
# File 'lib/runby_pace/pace_range.rb', line 21 def as_speed_range SpeedRange.new @fast.as_speed, @slow.as_speed end |
#to_s(format: :short) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/runby_pace/pace_range.rb', line 25 def to_s(format: :short) if @fast == @slow @fast.to_s(format: format) else @fast.to_s(format: format).sub(@fast.time.to_s, "#{@fast.time}-#{@slow.time}") end end |