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 Attribute Summary collapse
-
#number ⇒ Object
readonly
Returns the value of attribute number.
Instance Method Summary collapse
- #dump(index) ⇒ Object
-
#initialize(definitions, fit_entity) ⇒ FitRecord
constructor
A new instance of FitRecord.
- #read(io, entity, filter, record_counters) ⇒ Object
Constructor Details
#initialize(definitions, fit_entity) ⇒ FitRecord
Returns a new instance of FitRecord.
31 32 33 34 35 36 37 38 |
# File 'lib/fit4ruby/FitRecord.rb', line 31 def initialize(definitions, fit_entity) @definitions = definitions # It's a bit ugly that we have to pass the generated FitFileEntity to # the parser classes. But we need to have access to the developer field # definitions to parse them properly. @fit_entity = fit_entity @name = @number = @fields = nil end |
Instance Attribute Details
#number ⇒ Object (readonly)
Returns the value of attribute number.
29 30 31 |
# File 'lib/fit4ruby/FitRecord.rb', line 29 def number @number end |
Instance Method Details
#dump(index) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/fit4ruby/FitRecord.rb', line 82 def dump(index) return unless @fields begin puts "Message #{@number}: #{@name}" unless @fields.empty? @fields.sort.each do |field| puts field.to_s(index) end rescue Errno::EPIPE # Avoid ugly error message when aborting a less/more pipe. end end |
#read(io, entity, filter, record_counters) ⇒ Object
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 74 75 76 77 78 79 80 |
# File 'lib/fit4ruby/FitRecord.rb', line 40 def read(io, entity, filter, record_counters) header = FitRecordHeader.read(io) if header.compressed? # process compressed timestamp header time_offset = header.time_offset.snapshot end = header..snapshot if header.normal? && header..snapshot == 1 # process definition message definition = FitDefinition.read( io, entity, header.developer_data_flag.snapshot, @fit_entity.top_level_record) @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, @fit_entity) end self end |