Sha256: f047bd8f6f7e7a365c23f90ba641be05bb8a1a0faecfb298eb5cefbfee39443c

Contents?: true

Size: 796 Bytes

Versions: 30

Compression:

Stored size: 796 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

    def as_speed_range
      SpeedRange.new @fast.as_speed, @slow.as_speed
    end

    def to_s(format: :short)
      if @fast == @slow
        @fast.to_s(format: format)
      else
        @fast.to_s(format: format).sub("#{@fast.time}", "#{@fast.time}-#{@slow.time}")
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
runby_pace-0.6.143 lib/runby_pace/pace_range.rb
runby_pace-0.6.142 lib/runby_pace/pace_range.rb
runby_pace-0.6.141 lib/runby_pace/pace_range.rb
runby_pace-0.6.140 lib/runby_pace/pace_range.rb
runby_pace-0.6.139 lib/runby_pace/pace_range.rb
runby_pace-0.6.137 lib/runby_pace/pace_range.rb
runby_pace-0.6.136 lib/runby_pace/pace_range.rb
runby_pace-0.6.133 lib/runby_pace/pace_range.rb
runby_pace-0.6.132 lib/runby_pace/pace_range.rb
runby_pace-0.6.131 lib/runby_pace/pace_range.rb
runby_pace-0.6.130 lib/runby_pace/pace_range.rb
runby_pace-0.6.128 lib/runby_pace/pace_range.rb
runby_pace-0.6.127 lib/runby_pace/pace_range.rb
runby_pace-0.6.126 lib/runby_pace/pace_range.rb
runby_pace-0.6.125 lib/runby_pace/pace_range.rb
runby_pace-0.6.124 lib/runby_pace/pace_range.rb
runby_pace-0.6.123 lib/runby_pace/pace_range.rb
runby_pace-0.6.122 lib/runby_pace/pace_range.rb
runby_pace-0.6.121 lib/runby_pace/pace_range.rb
runby_pace-0.6.120 lib/runby_pace/pace_range.rb