Sha256: 56149597ad220b8d9eae0bed6174aa6a4d40072156a5e06397f7ff18ab5b54ed

Contents?: true

Size: 840 Bytes

Versions: 12

Compression:

Stored size: 840 Bytes

Contents

# frozen_string_literal: true

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
      freeze
    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.to_s, "#{@fast.time}-#{@slow.time}")
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
runby_pace-0.62.7 lib/runby_pace/pace_range.rb
runby_pace-0.62.5 lib/runby_pace/pace_range.rb
runby_pace-0.62.4 lib/runby_pace/pace_range.rb
runby_pace-0.62.3 lib/runby_pace/pace_range.rb
runby_pace-0.62.2 lib/runby_pace/pace_range.rb
runby_pace-0.2.50.111 lib/runby_pace/pace_range.rb
runby_pace-0.61.160 lib/runby_pace/pace_range.rb
runby_pace-0.61.159 lib/runby_pace/pace_range.rb
runby_pace-0.61.158 lib/runby_pace/pace_range.rb
runby_pace-0.61.157 lib/runby_pace/pace_range.rb
runby_pace-0.61.156 lib/runby_pace/pace_range.rb
runby_pace-0.61.155 lib/runby_pace/pace_range.rb