Module: Calculator

Included in:
Calcpace
Defined in:
lib/calcpace/calculator.rb

Overview

Module to calculate time, distance, pace and velocity

Instance Method Summary collapse

Instance Method Details

#checked_distance(time, velocity) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/calcpace/calculator.rb', line 64

def checked_distance(time, velocity)
  check_time(time)
  check_time(velocity)
  time_seconds = convert_to_seconds(time)
  velocity_seconds = convert_to_seconds(velocity)
  distance(time_seconds, velocity_seconds)
end

#checked_pace(time, distance) ⇒ Object



30
31
32
33
34
# File 'lib/calcpace/calculator.rb', line 30

def checked_pace(time, distance)
  check_time(time)
  seconds = convert_to_seconds(time)
  pace(seconds, distance)
end

#checked_time(velocity, distance) ⇒ Object



47
48
49
50
51
# File 'lib/calcpace/calculator.rb', line 47

def checked_time(velocity, distance)
  check_time(velocity)
  velocity_seconds = convert_to_seconds(velocity)
  time(velocity_seconds, distance)
end

#checked_velocity(time, distance) ⇒ Object



13
14
15
16
17
# File 'lib/calcpace/calculator.rb', line 13

def checked_velocity(time, distance)
  check_time(time)
  seconds = convert_to_seconds(time)
  velocity(seconds, distance)
end

#clock_pace(time, distance) ⇒ Object



36
37
38
39
# File 'lib/calcpace/calculator.rb', line 36

def clock_pace(time, distance)
  velocity_in_seconds = checked_pace(time, distance)
  convert_to_clocktime(velocity_in_seconds)
end

#clock_time(velocity, distance) ⇒ Object



53
54
55
56
# File 'lib/calcpace/calculator.rb', line 53

def clock_time(velocity, distance)
  total_time_in_seconds = checked_time(velocity, distance)
  convert_to_clocktime(total_time_in_seconds)
end

#clock_velocity(time, distance) ⇒ Object



19
20
21
22
# File 'lib/calcpace/calculator.rb', line 19

def clock_velocity(time, distance)
  velocity_in_seconds = checked_velocity(time, distance)
  convert_to_clocktime(velocity_in_seconds)
end

#distance(time, velocity) ⇒ Object



58
59
60
61
62
# File 'lib/calcpace/calculator.rb', line 58

def distance(time, velocity)
  check_positive(time)
  check_positive(velocity)
  time.to_f / velocity
end

#pace(time, distance) ⇒ Object



24
25
26
27
28
# File 'lib/calcpace/calculator.rb', line 24

def pace(time, distance)
  check_positive(distance)
  check_positive(time)
  time.to_f / distance
end

#time(velocity, distance) ⇒ Object



41
42
43
44
45
# File 'lib/calcpace/calculator.rb', line 41

def time(velocity, distance)
  check_positive(distance)
  check_positive(velocity)
  velocity * distance
end

#velocity(time, distance) ⇒ Object



7
8
9
10
11
# File 'lib/calcpace/calculator.rb', line 7

def velocity(time, distance)
  check_positive(distance)
  check_positive(time)
  distance.to_f / time
end