Sha256: 52c9be105b27ef8fbb95c5e8058604b3d15a803b913329e4f95d27aed4bf6740

Contents?: true

Size: 906 Bytes

Versions: 25

Compression:

Stored size: 906 Bytes

Contents

module Runby
  # An assortment of mathematical functions related to running.
  class RunMath
    def self.convert_pace_to_speed(pace)
      pace = Runby::RunbyTime.new(pace)
      (60 / pace.total_minutes).round(2)
    end

    def self.convert_speed_to_pace(units_per_hour)
      raise 'units_per_hour must be numeric' unless units_per_hour.is_a? Numeric
      Runby::RunbyTime.from_minutes(60.0 / units_per_hour)
    end

    def self.distance_traveled(pace, time)
      # TODO: I sense the need for a refactor...
      #  Consider extracting a new Pace class, which consists of Time + Units
      #  Then move this method to the new class, and give it a better name.
      pace = Runby::RunbyTime.new(pace)
      time = Runby::RunbyTime.new(time)

      divisor = pace.total_minutes / time.total_minutes
      distance_units_traveled = 1 / divisor
      return distance_units_traveled
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
runby_pace-0.6.106 lib/runby_pace/run_math.rb
runby_pace-0.6.105 lib/runby_pace/run_math.rb
runby_pace-0.6.104 lib/runby_pace/run_math.rb
runby_pace-0.6.103 lib/runby_pace/run_math.rb
runby_pace-0.6.102 lib/runby_pace/run_math.rb
runby_pace-0.6.101 lib/runby_pace/run_math.rb
runby_pace-0.6.100 lib/runby_pace/run_math.rb
runby_pace-0.6.98 lib/runby_pace/run_math.rb
runby_pace-0.6.99 lib/runby_pace/run_math.rb
runby_pace-0.6.97 lib/runby_pace/run_math.rb
runby_pace-0.6.94 lib/runby_pace/run_math.rb
runby_pace-0.6.91 lib/runby_pace/run_math.rb
runby_pace-0.6.90 lib/runby_pace/run_math.rb
runby_pace-0.6.89 lib/runby_pace/run_math.rb
runby_pace-0.6.88 lib/runby_pace/run_math.rb
runby_pace-0.6.87 lib/runby_pace/run_math.rb
runby_pace-0.5.86 lib/runby_pace/run_math.rb
runby_pace-0.5.85 lib/runby_pace/run_math.rb
runby_pace-0.4.84 lib/runby_pace/run_math.rb
runby_pace-0.4.83 lib/runby_pace/run_math.rb