Class: PaceConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/running_on_rails/pace_converter.rb

Instance Method Summary collapse

Constructor Details

#initialize(meters = 0, seconds = 1) ⇒ PaceConverter

Returns a new instance of PaceConverter.



2
3
4
5
# File 'lib/running_on_rails/pace_converter.rb', line 2

def initialize(meters = 0, seconds = 1)
  @seconds = seconds.to_i
  @distance = meters
end

Instance Method Details

#from_kms_hour(kms) ⇒ Object



30
31
32
33
34
35
# File 'lib/running_on_rails/pace_converter.rb', line 30

def from_kms_hour(kms)
  kms = (kms or 0).abs
  @distance = kms * 1000.0
  @seconds = 3600
  to_meters_sec
end

#from_meters_sec(meters) ⇒ Object



37
38
39
40
41
# File 'lib/running_on_rails/pace_converter.rb', line 37

def from_meters_sec(meters)
meters = (meters or 0).abs
@distance = meters
@seconds = 1
end

#from_miles_hour(miles) ⇒ Object



15
16
17
18
19
20
# File 'lib/running_on_rails/pace_converter.rb', line 15

def from_miles_hour(miles)
  miles = (miles or 0).abs
  @distance = miles * 1609.344
  @seconds = 3600
  to_meters_sec
end

#from_mins_km(mins, secs) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/running_on_rails/pace_converter.rb', line 22

def from_mins_km(mins, secs)
  mins = (mins or 0).abs.to_i
  secs = (secs or 0).abs.to_i
  @distance = 1000.0
  @seconds = (mins * 60) + secs
  to_meters_sec
end

#from_mins_mile(mins, secs) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/running_on_rails/pace_converter.rb', line 7

def from_mins_mile(mins, secs)
  mins = (mins or 0).abs.to_i
  secs = (secs or 0).abs.to_i
  @distance = 1609.344
  @seconds = (mins * 60) + secs
  to_meters_sec
end

#to_kms_hourObject



55
56
57
# File 'lib/running_on_rails/pace_converter.rb', line 55

def to_kms_hour
  ((@distance / @seconds) * 3.6).round(3)
end

#to_meters_secObject



59
60
61
62
63
64
65
# File 'lib/running_on_rails/pace_converter.rb', line 59

def to_meters_sec
  if @seconds != 0 
    ((@distance / @seconds)).round(3)
  else
    0.0
  end      
end

#to_miles_hourObject



47
48
49
# File 'lib/running_on_rails/pace_converter.rb', line 47

def to_miles_hour 
  ((@distance / @seconds) * 2.23694).round(3)
end

#to_mins_kmObject



51
52
53
# File 'lib/running_on_rails/pace_converter.rb', line 51

def to_mins_km
  (16.667 / (@distance / @seconds)).round(3)
end

#to_mins_mileObject



43
44
45
# File 'lib/running_on_rails/pace_converter.rb', line 43

def to_mins_mile
  (26.8224 / (@distance / @seconds)).round(3)
end