Class: Fit
- Inherits:
-
Object
- Object
- Fit
- Defined in:
- lib/fitreader/fit.rb
Instance Attribute Summary collapse
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
Instance Method Summary collapse
- #digest ⇒ Object
-
#initialize(io) ⇒ Fit
constructor
A new instance of Fit.
- #type(name) ⇒ Object
Constructor Details
#initialize(io) ⇒ Fit
Returns a new instance of Fit.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/fitreader/fit.rb', line 14 def initialize(io) @header = FileHeader.new(io) finished = [] begin defs = {} until (io.pos - 14) >= header.num_record_bytes h = RecordHeader.new(io) if h.definition? d = DefinitionRecord.new(io, h.) finished << defs[d.local_num] if defs.key? d.local_num defs[d.local_num] = d elsif h.data? d = defs[h.] if d.local_num != h. d.data_records << DataRecord.new(io, d) else # TODO implement timestamps end end finished.push(*defs.values) rescue => e puts "error: #{e}\n#{e.backtrace}" end io.close = finished.group_by(&:global_msg_num) .map { |x| Message.new x } .reject { |x| x.data.nil? } end |
Instance Attribute Details
#header ⇒ Object (readonly)
Returns the value of attribute header.
12 13 14 |
# File 'lib/fitreader/fit.rb', line 12 def header @header end |
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
12 13 14 |
# File 'lib/fitreader/fit.rb', line 12 def end |
Instance Method Details
#digest ⇒ Object
42 43 44 |
# File 'lib/fitreader/fit.rb', line 42 def digest Hash[.map { |x| [x.name, x.data.count] }] end |
#type(name) ⇒ Object
46 47 48 |
# File 'lib/fitreader/fit.rb', line 46 def type(name) .find { |x| x.name == name } end |