Class: Fitreader::Definition
- Inherits:
-
Object
- Object
- Fitreader::Definition
- Defined in:
- lib/fitreader/definition.rb
Instance Attribute Summary collapse
-
#field_definitions ⇒ Object
Returns the value of attribute field_definitions.
-
#fit_msg ⇒ Object
Returns the value of attribute fit_msg.
-
#global_num ⇒ Object
Returns the value of attribute global_num.
-
#local_num ⇒ Object
Returns the value of attribute local_num.
-
#name ⇒ Object
Returns the value of attribute name.
-
#num_fields ⇒ Object
Returns the value of attribute num_fields.
Instance Method Summary collapse
- #add_fields(bytes) ⇒ Object
- #content_length ⇒ Object
- #field(id) ⇒ Object
-
#initialize(msg_num, bytes) ⇒ Definition
constructor
A new instance of Definition.
- #message_type ⇒ Object
Constructor Details
#initialize(msg_num, bytes) ⇒ Definition
Returns a new instance of Definition.
6 7 8 9 10 11 12 13 |
# File 'lib/fitreader/definition.rb', line 6 def initialize(msg_num, bytes) @local_num = msg_num @architecture = bytes[1].unpack('C').first @global_num = bytes[2..3].unpack('v').first @fit_msg = Static.[@global_num] @name = Static.enums[:enum_mesg_num][@global_num] @num_fields = bytes[4].unpack('C').first end |
Instance Attribute Details
#field_definitions ⇒ Object
Returns the value of attribute field_definitions.
5 6 7 |
# File 'lib/fitreader/definition.rb', line 5 def field_definitions @field_definitions end |
#fit_msg ⇒ Object
Returns the value of attribute fit_msg.
5 6 7 |
# File 'lib/fitreader/definition.rb', line 5 def fit_msg @fit_msg end |
#global_num ⇒ Object
Returns the value of attribute global_num.
5 6 7 |
# File 'lib/fitreader/definition.rb', line 5 def global_num @global_num end |
#local_num ⇒ Object
Returns the value of attribute local_num.
5 6 7 |
# File 'lib/fitreader/definition.rb', line 5 def local_num @local_num end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/fitreader/definition.rb', line 5 def name @name end |
#num_fields ⇒ Object
Returns the value of attribute num_fields.
5 6 7 |
# File 'lib/fitreader/definition.rb', line 5 def num_fields @num_fields end |
Instance Method Details
#add_fields(bytes) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/fitreader/definition.rb', line 19 def add_fields(bytes) bytes.chars.each_slice(3) do |x| fd = FieldDefinition.new(@global_num, x) (@field_definitions ||= []).push(fd) end end |
#content_length ⇒ Object
26 27 28 |
# File 'lib/fitreader/definition.rb', line 26 def content_length @field_definitions.inject(0){|sum,x| sum + x.size} end |
#field(id) ⇒ Object
15 16 17 |
# File 'lib/fitreader/definition.rb', line 15 def field(id) @field_definitions.find { |x| x.def_num == id } end |
#message_type ⇒ Object
30 31 32 |
# File 'lib/fitreader/definition.rb', line 30 def Static.[@global_num] end |