Class: Runby::SpeedRange
- Inherits:
-
RunbyRange
- Object
- RunbyRange
- Runby::SpeedRange
- Defined in:
- lib/runby_pace/speed_range.rb
Overview
Represents a range of speeds, from fast to slow.
Instance Attribute Summary
Attributes inherited from RunbyRange
Instance Method Summary collapse
- #as_pace_range ⇒ Object
-
#initialize(fast, slow) ⇒ SpeedRange
constructor
A new instance of SpeedRange.
- #to_s(format: :short) ⇒ Object
Constructor Details
#initialize(fast, slow) ⇒ SpeedRange
Returns a new instance of SpeedRange.
8 9 10 11 12 13 14 |
# File 'lib/runby_pace/speed_range.rb', line 8 def initialize(fast, slow) raise "Invalid fast speed value: #{fast}" unless fast.is_a?(Numeric) || fast.is_a?(Speed) raise "Invalid slow speed value: #{slow}" unless slow.is_a?(Numeric) || slow.is_a?(Speed) @fast = Runby::Speed.new(fast) @slow = Runby::Speed.new(slow) freeze end |
Instance Method Details
#as_pace_range ⇒ Object
16 17 18 |
# File 'lib/runby_pace/speed_range.rb', line 16 def as_pace_range Runby::PaceRange.new @fast.as_pace, @slow.as_pace end |
#to_s(format: :short) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/runby_pace/speed_range.rb', line 20 def to_s(format: :short) if @fast == @slow @fast.to_s(format: format) else fast_multiplier = format('%g', @fast.distance.multiplier.round(2)) slow_multiplier = format('%g', @slow.distance.multiplier.round(2)) @fast.to_s(format: format).sub(fast_multiplier.to_s, "#{fast_multiplier}-#{slow_multiplier}") end end |