lib/fit4ruby/FitDataRecord.rb in fit4ruby-0.0.7 vs lib/fit4ruby/FitDataRecord.rb in fit4ruby-0.0.8

- old
+ new

@@ -1,11 +1,11 @@ #!/usr/bin/env ruby -w # encoding: UTF-8 # # = FitDataRecord.rb -- Fit4Ruby - FIT file processing library for Ruby # -# Copyright (c) 2014 by Chris Schlaeger <cs@taskjuggler.org> +# 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. # @@ -17,10 +17,15 @@ class FitDataRecord include Converters + RecordOrder = [ 'user_profile', 'device_info', 'data_sources', 'event', + 'record', 'lap', 'session', 'personal_records' ] + + attr_reader :message + def initialize(record_id) @message = GlobalFitMessages.find_by_name(record_id) # Create instance variables that correspond to every field of the # corresponding FIT data record. @@ -89,10 +94,13 @@ true end def <=>(fdr) - @timestamp <=> fdr.timestamp + @timestamp == fdr.timestamp ? + RecordOrder.index(@message.name) <=> + RecordOrder.index(fdr.message.name) : + @timestamp <=> fdr.timestamp end def write(io, id_mapper) # Construct a GlobalFitMessage object that matches exactly the provided # set of fields. It does not contain any AltField objects.