fit_parser 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cfe16c1aae89815b69c6e91a5fdc5da00755a8a3
4
- data.tar.gz: 37f28492ce843593331c48abd109359e80b290a0
3
+ metadata.gz: 26a162b17897f536d316acc8e36dad49d36a3a72
4
+ data.tar.gz: 597240fbd8ee2fef1a95e1165e9a1fcb95f1948d
5
5
  SHA512:
6
- metadata.gz: 8e6191854d0c785710063ca83ec4d4fda9fc0f2e39a4dde31a85595f2678037ef4a3d8fcfebcb175f97074207cff27ab86a521be9ee827847b138fb29200dcb9
7
- data.tar.gz: 07caf2f96cde4c0f98386267cd4199f0c7c6a661794db9e51e7e76838f19bdf01753f8b31c26ea5e4e10b35e46e20c26678e054baed82a948920c14ab3afd395
6
+ metadata.gz: 67a8ee06d504f0a96a7a3a3b1619692b287192830fdeb252c701dad9f7eb7dfb8dc1084ab36d7ef640ce2955110c099a6f29e16699c9734f9b8a77d2b729f829
7
+ data.tar.gz: 7c4795cb5492141343f2f6c50dc3b866b6a3101bfc6b05a56ec5cc6403adaf5befaf0bb14644c2d0df4ca52172094893f7f2ba3f963b0bb9bde68073a39d61de
@@ -1,8 +1,7 @@
1
1
  module FitParser
2
2
  class File
3
3
  class Data < BinData::Record
4
-
5
- class_attribute :global_message_number, :instance_writer => false
4
+ class_attribute :global_message_number, instance_writer: false
6
5
 
7
6
  def self.generate(definition)
8
7
  msg_num = definition.global_message_number.snapshot
@@ -20,15 +19,15 @@ module FitParser
20
19
  RUBY
21
20
 
22
21
  definition.fields.each do |field|
23
- code = ""
22
+ code = ''
24
23
 
25
24
  # in case the field size is a multiple of the field length, we must build an array
26
- if (field.type != "string" and field.size > field.length)
25
+ if field.type != 'string' && field.size > field.length
27
26
  code << "array :#{field.raw_name}, :type => :#{field.type}, :initial_length => #{field.size/field.length}\n"
28
27
  else
29
28
  # string are not null terminated when they have exactly the lenght of the field
30
29
  code << "#{field.type} :#{field.raw_name}"
31
- if field.type == "string"
30
+ if field.type == 'string'
32
31
  code << ", :read_length => #{field.size}, :trim_padding => true"
33
32
  end
34
33
  code << "\n"
@@ -52,48 +51,46 @@ module FitParser
52
51
  end
53
52
  RUBY
54
53
 
55
- class_eval code , __FILE__, __LINE__ + 1
54
+ class_eval code, __FILE__, __LINE__ + 1
56
55
  end
57
-
56
+
58
57
  private
59
- # return the dynamic value if relevant
60
- # otherwise, it returns value (scaled if necessary)
61
- def get_value raw_value, raw_type, raw_scale, dyn_data
62
- val = get_dyn_value(dyn_data, raw_value)
63
- return val unless val.nil?
64
- if raw_scale
65
- if raw_value.is_a? Enumerable
66
- raw_value.map { |elt| elt / raw_scale }
67
- else
68
- raw_value / raw_scale
69
- end
58
+
59
+ # return the dynamic value if relevant
60
+ # otherwise, it returns value (scaled if necessary)
61
+ def get_value(raw_value, raw_type, raw_scale, dyn_data)
62
+ val = get_dyn_value(dyn_data, raw_value)
63
+ return val unless val.nil?
64
+ if raw_scale
65
+ if raw_value.is_a? Enumerable
66
+ raw_value.map { |elt| elt / raw_scale }
70
67
  else
71
- get_real_value raw_type, raw_value
68
+ raw_value / raw_scale
72
69
  end
70
+ else
71
+ get_real_value raw_type, raw_value
73
72
  end
73
+ end
74
74
 
75
- # return the value based on real type
76
- def get_real_value( real_type, raw_value)
77
- type = Type.get_type(real_type.to_sym)
78
- # TODO: manage case where an array is returned
79
- type ? type.value(raw_value) : raw_value
80
- end
75
+ # return the value based on real type
76
+ def get_real_value(real_type, raw_value)
77
+ type = Type.get_type(real_type.to_sym)
78
+ # TODO: manage case where an array is returned
79
+ type ? type.value(raw_value) : raw_value
80
+ end
81
81
 
82
- def get_dyn_value dyn_data, raw_value
83
- return nil if dyn_data.nil?
84
- dyn_data.each do |key, dyn|
85
- # make sure method exist before calling send (all fields are not always defined)
86
- if( self.respond_to?("raw_#{dyn[:ref_field_name]}") &&
87
- dyn[:ref_field_values].include?(self.send("raw_#{dyn[:ref_field_name]}")))
88
- return get_real_value(dyn[:type], raw_value)
89
- end
82
+ def get_dyn_value(dyn_data, raw_value)
83
+ return nil if dyn_data.nil?
84
+ dyn_data.each do |key, dyn|
85
+ # make sure method exist before calling send (all fields are not always defined)
86
+ if respond_to?("raw_#{dyn[:ref_field_name]}") && dyn[:ref_field_values].include?(send("raw_#{dyn[:ref_field_name]}"))
87
+ return get_real_value(dyn[:type], raw_value)
90
88
  end
91
- nil
92
89
  end
93
-
90
+ nil
91
+ end
94
92
  end
95
93
  end
96
-
97
94
  end
98
95
  end
99
96
  end
@@ -1,7 +1,6 @@
1
1
  module FitParser
2
2
  class File
3
3
  class Definition < BinData::Record
4
-
5
4
  class Field < BinData::Record
6
5
  hide :reserved_bits
7
6
 
@@ -14,7 +13,7 @@ module FitParser
14
13
  def data
15
14
  @data ||= Definitions.get_field(parent.parent.global_message_number.snapshot,
16
15
  field_definition_number.snapshot) ||
17
- { :name => "field_#{field_definition_number.snapshot}", :scale => nil }
16
+ { name: "field_#{field_definition_number.snapshot}", scale: nil }
18
17
  end
19
18
 
20
19
  def dyn_data
@@ -58,13 +57,13 @@ module FitParser
58
57
  # some cases found where string has the max field length
59
58
  # and is therefore not null terminated
60
59
  @length = 1
61
- "string"
60
+ 'string'
62
61
  when 8
63
62
  @length = 4
64
- "float"
63
+ 'float'
65
64
  when 9
66
65
  @length = 8
67
- "double"
66
+ 'double'
68
67
  when 10 # uint8z
69
68
  build_int_type 8, false
70
69
  when 11 # uint16z
@@ -74,7 +73,7 @@ module FitParser
74
73
  when 13 # array of bytes
75
74
  build_int_type 8, false
76
75
  else
77
- raise "Can't map base_type_number #{base_type_number} to a data type"
76
+ fail "Can't map base_type_number #{base_type_number} to a data type"
78
77
  end
79
78
  end
80
79
 
@@ -82,7 +81,7 @@ module FitParser
82
81
  def size
83
82
  field_size
84
83
  end
85
-
84
+
86
85
  # return the length in byte of the given type
87
86
  def length
88
87
  @length
@@ -92,19 +91,19 @@ module FitParser
92
91
 
93
92
  def build_int_type(length, signed)
94
93
  # @length is in byte not in bits, so divide by 8
95
- @length = length/8
94
+ @length = length / 8
96
95
  (signed ? '' : 'u') << 'int' << length.to_s
97
96
  end
98
97
  end
99
98
 
100
- skip :length => 1
99
+ skip length: 1
101
100
  bit8 :architecture
102
- choice :global_message_number, :selection => :architecture do
101
+ choice :global_message_number, selection: :architecture do
103
102
  uint16le 0
104
103
  uint16be 1
105
104
  end
106
105
  bit8 :field_count
107
- array :fields, :type => Field, :initial_length => :field_count
106
+ array :fields, type: Field, initial_length: :field_count
108
107
 
109
108
  def endianness
110
109
  architecture.snapshot == 0 ? :little : :big
@@ -113,8 +112,6 @@ module FitParser
113
112
  def record_type
114
113
  :definition
115
114
  end
116
-
117
115
  end
118
116
  end
119
117
  end
120
-