Sha256: 5e742add107cc3a81e04952ac787bfc09fa2e5c4c9d55cea9d0486ace103140f

Contents?: true

Size: 931 Bytes

Versions: 3

Compression:

Stored size: 931 Bytes

Contents

require_relative 'runby_range'

module Runby
  # Represents a range of paces, from fast to slow.
  class PaceRange < RunbyRange
    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

    # Create a new pace range from an existing speed range.
    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

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
runby_pace-0.6.103 lib/runby_pace/pace_range.rb
runby_pace-0.6.102 lib/runby_pace/pace_range.rb
runby_pace-0.6.101 lib/runby_pace/pace_range.rb