lib/fit4ruby/FitFile.rb in fit4ruby-0.0.4 vs lib/fit4ruby/FitFile.rb in fit4ruby-0.0.5

- old
+ new

@@ -1,19 +1,20 @@ #!/usr/bin/env ruby -w # encoding: UTF-8 # # = FitFile.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. # require 'fit4ruby/Log' require 'fit4ruby/FitHeader' +require 'fit4ruby/FitFileEntity' require 'fit4ruby/FitRecord' require 'fit4ruby/FitFilter' require 'fit4ruby/FitMessageIdMapper' require 'fit4ruby/GlobalFitMessages' require 'fit4ruby/GlobalFitDictionaries' @@ -37,33 +38,33 @@ header = FitHeader.read(io) header.check check_crc(io, header.end_pos) - activity = Activity.new + entity = FitFileEntity.new # This Array holds the raw data of the records that may be needed to # dump a human readable form of the FIT file. records = [] # This hash will hold a counter for each record type. The counter is # incremented each time the corresponding record type is found. record_counters = Hash.new { 0 } while io.pos < header.end_pos record = FitRecord.new(definitions) - record.read(io, activity, filter, record_counters) + record.read(io, entity, filter, record_counters) records << record if filter end io.close header.dump if filter && filter.record_numbers.nil? dump_records(records) if filter - activity.check - activity + entity.check + entity.top_level_record end - def write(file_name, activity) + def write(file_name, top_level_record) begin io = ::File.open(file_name, 'wb+') rescue StandardError => e Log.critical("Cannot open FIT file '#{file_name}'", e) end @@ -72,10 +73,10 @@ header = FitHeader.new start_pos = header.header_size # Move the pointer behind the header section. io.seek(start_pos) id_mapper = FitMessageIdMapper.new - activity.write(io, id_mapper) + top_level_record.write(io, id_mapper) end_pos = io.pos crc = write_crc(io, start_pos, end_pos) # Complete the data of the header section and write it at the start of