Class: Fit4Ruby::FitRecord
- Inherits:
-
Object
- Object
- Fit4Ruby::FitRecord
- Defined in:
- lib/fit4ruby/FitRecord.rb
Overview
The FitRecord is a basic building block of a FIT file. It can either contain a definition of a message record or an actual message record with FIT data. A FIT record always starts with a header that describes what kind of record this is.
Instance Method Summary collapse
- #dump ⇒ Object
-
#initialize(definitions) ⇒ FitRecord
constructor
A new instance of FitRecord.
- #read(io, entity, filter, record_counters) ⇒ Object
Constructor Details
#initialize(definitions) ⇒ FitRecord
Returns a new instance of FitRecord.
28 29 30 31 |
# File 'lib/fit4ruby/FitRecord.rb', line 28 def initialize(definitions) @definitions = definitions @name = @number = @fields = nil end |
Instance Method Details
#dump ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/fit4ruby/FitRecord.rb', line 75 def dump return unless @fields begin puts "Message #{@number}: #{@name}" unless @fields.empty? @fields.each do |type, name, value| puts " [#{"%-7s" % type}] #{name}: " + "#{value}" end rescue Errno::EPIPE # Avoid ugly error message when aborting a less/more pipe. end end |
#read(io, entity, filter, record_counters) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/fit4ruby/FitRecord.rb', line 33 def read(io, entity, filter, record_counters) header = FitRecordHeader.read(io) if !header.compressed? # process normal headers = header..snapshot if header..snapshot == 1 # process definition message definition = FitDefinition.read(io) @definitions[] = FitMessageRecord.new(definition) else # process data message definition = @definitions[] unless definition Log.fatal "Undefined local message type: #{}" end if filter @number = @definitions[]. index = (record_counters[@number] += 1) # Check if we have a filter defined to collect raw dumps of the # data in the message records. The dump is collected in @fields # for later output. if (filter.record_numbers.nil? || filter.record_numbers.include?(@number)) && (filter.record_indexes.nil? || filter.record_indexes.include?(index)) @name = definition.name @fields = [] end end definition.read(io, entity, filter, @fields) end else # process compressed timestamp header time_offset = header.time_offset Log.fatal "Support for compressed headers not yet implemented" end self end |