Sha256: 9fa4f0cd1927f5e637dcc9d19b21d389c061ba0e7874712a4a96e509a319f61c

Contents?: true

Size: 839 Bytes

Versions: 1

Compression:

Stored size: 839 Bytes

Contents

module Stressfactor
  class Interval
    attr_accessor :start_point, :end_point

    def initialize(start_point, end_point)
      @start_point = start_point
      @end_point = end_point
    end

    # time in seconds
    def time(options={})
      delta = end_point.time - start_point.time
      delta /= 60.0 if options[:units] == :minutes
      delta
    end

    # distance in km
    def distance
      end_point.haversine_distance_from(start_point)
    end

    # grade in percent incline/decline
    def grade
      elevation_change = end_point.elevation - start_point.elevation
      # Normalize to meters
      distance_change = distance * 1000
      radians = Math.atan(elevation_change / distance_change)
      180 * radians / Math::PI
    end

    def to_s
      "i: #{time}s | #{distance * 1000}m | #{grade}%"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stressfactor-0.0.1 lib/stressfactor/interval.rb