Class: Runby::RunMath

Inherits:
Object
  • Object
show all
Defined in:
lib/runby_pace/run_math.rb

Overview

An assortment of mathematical functions related to running.

Class Method Summary collapse

Class Method Details

.convert_pace_to_speed(pace) ⇒ Object



4
5
6
7
# File 'lib/runby_pace/run_math.rb', line 4

def self.convert_pace_to_speed(pace)
  pace = Runby::RunbyTime.new(pace)
  (60 / pace.total_minutes).round(2)
end

.convert_speed_to_pace(units_per_hour) ⇒ Object



9
10
11
12
# File 'lib/runby_pace/run_math.rb', line 9

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

.distance_traveled(pace, time) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/runby_pace/run_math.rb', line 14

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