Sha256: 1e56de6ae58cd24db6afd65938b5b520899fb5fe14de796ab04078289466bb92

Contents?: true

Size: 1.68 KB

Versions: 24

Compression:

Stored size: 1.68 KB

Contents

#!/usr/bin/env ruby -w
# encoding: UTF-8
#
# = DeviceInfo.rb -- Fit4Ruby - FIT file processing library for Ruby
#
# Copyright (c) 2014, 2015 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

  class DeviceInfo < FitDataRecord

    def initialize(field_values = {})
      super('device_info')
      set_field_values(field_values)
    end

    # Ensure that FitDataRecords have a deterministic sequence. Device infos
    # are sorted by device_index.
    def <=>(fdr)
      @timestamp == fdr.timestamp ?
        @message.name == fdr.message.name ?
          @device_index <=> fdr.device_index :
          RecordOrder.index(@message.name) <=>
            RecordOrder.index(fdr.message.name) :
        @timestamp <=> fdr.timestamp
    end

    def check(index)
      unless @device_index
        Log.fatal 'device info record must have a device_index'
      end
      if @device_index == 0
        unless @manufacturer
          Log.fatal 'device info record 0 must have a manufacturer field set'
        end
        if @manufacturer == 'garmin'
          unless @garmin_product
            Log.fatal 'device info record 0 must have a garman_product ' +
                      'field set'
          end
        else
          unless @product
            Log.fatal 'device info record 0 must have a product field set'
          end
        end
        if @serial_number.nil?
          Log.fatal 'device info record 0 must have a serial number set'
        end
      end
    end

  end

end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
fit4ruby-3.5.0 lib/fit4ruby/DeviceInfo.rb
fit4ruby-3.4.0 lib/fit4ruby/DeviceInfo.rb
fit4ruby-3.3.0 lib/fit4ruby/DeviceInfo.rb
fit4ruby-3.2.0 lib/fit4ruby/DeviceInfo.rb
fit4ruby-3.1.0 lib/fit4ruby/DeviceInfo.rb
fit4ruby-3.0.0 lib/fit4ruby/DeviceInfo.rb
fit4ruby-2.0.0 lib/fit4ruby/DeviceInfo.rb
fit4ruby-1.7.0 lib/fit4ruby/DeviceInfo.rb
fit4ruby-1.6.2 lib/fit4ruby/DeviceInfo.rb
fit4ruby-1.6.1 lib/fit4ruby/DeviceInfo.rb
fit4ruby-1.6.0 lib/fit4ruby/DeviceInfo.rb
fit4ruby-1.5.1 lib/fit4ruby/DeviceInfo.rb
fit4ruby-1.5.0 lib/fit4ruby/DeviceInfo.rb
fit4ruby-1.4.0 lib/fit4ruby/DeviceInfo.rb
fit4ruby-1.3.0 lib/fit4ruby/DeviceInfo.rb
fit4ruby-1.2.0 lib/fit4ruby/DeviceInfo.rb
fit4ruby-1.1.0 lib/fit4ruby/DeviceInfo.rb
fit4ruby-1.0.1 lib/fit4ruby/DeviceInfo.rb
fit4ruby-1.0.0 lib/fit4ruby/DeviceInfo.rb
fit4ruby-0.0.12 lib/fit4ruby/DeviceInfo.rb