Class: Fit4Ruby::FitFileEntity
- Inherits:
-
Object
- Object
- Fit4Ruby::FitFileEntity
- Defined in:
- lib/fit4ruby/FitFileEntity.rb
Overview
The FIT file is a generic container for all kinds of data. This could be activity data, config files, workout definitions, etc. All data is stored in FIT message records. Also the information what kind of FIT file this is is stored in such a record. When we start reading the file, we actually don’t know what kind of file it is until we find the right record to tell us. Since we already need to have gathered some information at this point, we use this utility class to store the read data until we know what Ruby objec we need to use to store it for later consumption.
Instance Attribute Summary collapse
-
#top_level_record ⇒ Object
readonly
Returns the value of attribute top_level_record.
Instance Method Summary collapse
-
#check ⇒ Object
Check the consistency of the top-level object.
-
#initialize ⇒ FitFileEntity
constructor
Create a FitFileEntity.
-
#new_fit_data_record(type) ⇒ Object
Add a new data record to the top-level object.
-
#set_type(type) ⇒ Object
Set what kind of FIT file we are dealing with.
-
#write(io, id_mapper) ⇒ Object
Write the top-level object into a IO stream.
Constructor Details
#initialize ⇒ FitFileEntity
Create a FitFileEntity.
31 32 33 |
# File 'lib/fit4ruby/FitFileEntity.rb', line 31 def initialize @top_level_record = nil end |
Instance Attribute Details
#top_level_record ⇒ Object (readonly)
Returns the value of attribute top_level_record.
28 29 30 |
# File 'lib/fit4ruby/FitFileEntity.rb', line 28 def top_level_record @top_level_record end |
Instance Method Details
#check ⇒ Object
Check the consistency of the top-level object.
71 72 73 74 |
# File 'lib/fit4ruby/FitFileEntity.rb', line 71 def check return false unless @top_level_record @top_level_record.check end |
#new_fit_data_record(type) ⇒ Object
Add a new data record to the top-level object.
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/fit4ruby/FitFileEntity.rb', line 59 def new_fit_data_record(type) return nil unless @top_level_record # We already have a record for the top-level type. Just return it. return @top_level_record if type == @type # For all other types, we need to create a new record inside the # top-level record. @top_level_record.new_fit_data_record(type) end |
#set_type(type) ⇒ Object
Set what kind of FIT file we are dealing with. a derivative of FitDataRecord.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/fit4ruby/FitFileEntity.rb', line 38 def set_type(type) if @top_level_record Log.fatal "FIT file type has already been set to " + "#{@top_level_record.class}" end case type when 4, 'activity' @top_level_record = Activity.new @type = 'activity' when 32, 'monitoring_b' @top_level_record = Monitoring_B.new @type = 'monitoring_b' else Log.error "Unsupported FIT file type #{type}" return nil end @top_level_record end |
#write(io, id_mapper) ⇒ Object
Write the top-level object into a IO stream.
77 78 79 80 |
# File 'lib/fit4ruby/FitFileEntity.rb', line 77 def write(io, id_mapper) return unless @top_level_record @top_level_record.write(io, id_mapper) end |