Sha256: 20b5183af18a8a903a450b21c9f6f8c28748b71317e27c42fd6ec043842adc41

Contents?: true

Size: 922 Bytes

Versions: 1

Compression:

Stored size: 922 Bytes

Contents

module RunbyPace
  # An assortment of mathematical functions related to running.
  class RunMath
    def self.convert_pace_to_speed(pace)
      pace = RunbyPace::PaceTime.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
      RunbyPace::PaceTime.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 = RunbyPace::PaceTime.new(pace)
      time = RunbyPace::PaceTime.new(time)

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
runby_pace-0.2.74 lib/runby_pace/run_math.rb