Class: Runby::PaceRange

Inherits:
RunbyRange show all
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

#fast, #slow

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fast, slow, distance_units = :km) ⇒ PaceRange

Returns a new instance of PaceRange.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/runby_pace/pace_range.rb', line 6

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
end

Class Method Details

.from_speed_range(speed_range) ⇒ Object

Create a new pace range from an existing speed range.



19
20
21
22
23
# File 'lib/runby_pace/pace_range.rb', line 19

def self.from_speed_range(speed_range)
  fast = RunMath.convert_speed_to_pace speed_range.fast
  slow = RunMath.convert_speed_to_pace speed_range.slow
  PaceRange.new fast, slow
end

Instance Method Details

#to_sObject



25
26
27
28
29
30
31
# File 'lib/runby_pace/pace_range.rb', line 25

def to_s
  if @fast == @slow
    @fast.to_s
  else
    "#{@fast.time}-#{@slow.time} per #{@fast.distance.pluralized_uom}"
  end
end