Sha256: 5894b2284120244922ea69a573a8429e3415b51b3da030211cae005c7bd08b5a

Contents?: true

Size: 1.26 KB

Versions: 3

Compression:

Stored size: 1.26 KB

Contents

#!/usr/bin/env ruby -w
# encoding: UTF-8
#
# = Record.rb -- Fit4Ruby - FIT file processing library for Ruby
#
# Copyright (c) 2014 by Chris Schlaeger <cs@taskjuggler.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#

require 'fit4ruby/FitDataRecord'

module Fit4Ruby

  # The Record corresponds to the record FIT message. A Record is a basic set
  # of primary measurements that are associated with a certain timestamp.
  class Record < FitDataRecord

    # Create a new Record object.
    # @param field_values [Hash] Hash that provides initial values for certain
    #        fields.
    def initialize(field_values = {})
      super('record')
      @meta_field_units['pace'] = 'min/km'
      @meta_field_units['run_cadence'] = 'spm'
      set_field_values(field_values)
    end

    def run_cadence
      if @cadence && @fractional_cadence
        (@cadence + @fractional_cadence) * 2
      elsif @cadence
        @cadence * 2
      else
        nil
      end
    end

    # Convert the 'speed' field into a running pace. The pace is measured in
    # minutes per Kilometer.
    def pace
      1000.0 / (@speed * 60.0)
    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fit4ruby-0.0.5 lib/fit4ruby/Record.rb
fit4ruby-0.0.4 lib/fit4ruby/Record.rb
fit4ruby-0.0.3 lib/fit4ruby/Record.rb