lib/fit_parser/file/data.rb in fit_parser-1.0.8 vs lib/fit_parser/file/data.rb in fit_parser-1.0.9
- old
+ new
@@ -20,17 +20,18 @@
end
RUBY
definition.fields_arr.each do |field|
code = ''
+ field_raw_name_sanitized = field.raw_name.gsub('/', '_').gsub('+', '').gsub('%', '').gsub('-', '')
# in case the field size is a multiple of the field length, we must build an array
if field.type != 'string' && field.size > field.length
- code << "array :#{field.raw_name}, :type => :#{field.type}, :initial_length => #{field.size/field.length}\n"
+ code << "array :#{field_raw_name_sanitized}, :type => :#{field.type}, :initial_length => #{field.size/field.length}\n"
else
# string are not null terminated when they have exactly the lenght of the field
- code << "#{field.type} :#{field.raw_name}"
+ code << "#{field.type} :#{field_raw_name_sanitized}"
if field.type == 'string'
code << ", :read_length => #{field.size}, :trim_padding => true"
end
code << "\n"
end
@@ -52,11 +53,11 @@
code << "dyn = #{field.dyn_data}\n"
else
code << "dyn = nil\n"
end
code << <<-RUBY
- get_value #{field.raw_name}.snapshot, '#{field.real_type}', scale, dyn
+ get_value #{field_raw_name_sanitized}.snapshot, '#{field.real_type}', scale, dyn
end
RUBY
class_eval code, __FILE__, __LINE__ + 1
end
@@ -68,17 +69,18 @@
data = developer_data[field[:field_number].to_s]
field.base_type_number = data[:raw_field_2]
field.name = data[:raw_field_3].downcase.gsub(' ', '_').gsub('.', '').gsub('%', '')
field.scale = data[:raw_field_6] && data[:raw_field_6] != 255 ? data[:raw_field_6] : nil
code = ''
+ field_raw_name_sanitized = field.raw_name.gsub('/', '_').gsub('+', '').gsub('%', '').gsub('-', '')
# in case the field size is a multiple of the field length, we must build an array
if field.type != 'string' && field.field_size > field.length
- code << "array :#{field.raw_name}, :type => :#{field.type}, :initial_length => #{field.field_size/field.length}\n"
+ code << "array :#{field_raw_name_sanitized}, :type => :#{field.type}, :initial_length => #{field.field_size/field.length}\n"
else
# string are not null terminated when they have exactly the lenght of the field
- code << "#{field.type} :#{field.raw_name.gsub('/', '_').gsub('+', '').gsub('%', '')}"
+ code << "#{field.type} :#{field_raw_name_sanitized}"
if field.type == 'string'
code << ", :read_length => #{field.field_size}, :trim_padding => true"
end
code << "\n"
end
@@ -101,10 +103,10 @@
else
code << "dyn = nil\n"
end
code << <<-RUBY
- get_value #{field.raw_name}.snapshot, '#{field.real_type}', scale, dyn
+ get_value #{field_raw_name_sanitized}.snapshot, '#{field.real_type}', scale, dyn
end
RUBY
class_eval code, __FILE__, __LINE__ + 1
end