fit_parser 0.0.8 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,9 +13,15 @@ module FitParser
13
13
  def read(io)
14
14
  @header = Header.read(io)
15
15
  definitions = {}
16
+ dev_definitions = {}
16
17
  while io.pos < @header.end_pos
17
- record = Record.new(definitions)
18
+ record = Record.new(definitions, dev_definitions)
18
19
  @records << record.read(io)
20
+ content = record.content
21
+ if content[:raw_field_0] == 0
22
+ dev_definitions[content[:raw_field_0].to_s] ||= {}
23
+ dev_definitions[content[:raw_field_0].to_s][content[:raw_field_1].to_s] = content
24
+ end
19
25
  definitions = record.definitions
20
26
  end
21
27
  @crc = io.read(2)
@@ -1,3 +1,3 @@
1
1
  module FitParser
2
- VERSION = '0.0.8'
2
+ VERSION = '1.0.0'
3
3
  end
data/lib/fit_parser.rb CHANGED
@@ -11,6 +11,7 @@ require 'fit_parser/file/definition'
11
11
  require 'fit_parser/file/data'
12
12
  require 'fit_parser/file/definitions'
13
13
  require 'fit_parser/version'
14
+ require 'bindata/dsl_field_validator'
14
15
 
15
16
  module FitParser
16
17
  def self.load_file(path)
@@ -20,6 +20,7 @@ describe FitParser::File::Data do
20
20
  @fields = FitParser::File::Definitions.fields
21
21
  @dyn_fields = FitParser::File::Definitions.dyn_fields
22
22
  # force a fake definition for scaling of arrays
23
+ FitParser::File::Definitions.fields[2].delete(2)
23
24
  FitParser::File::Definitions.add_field(
24
25
  2, 2, 'field_array', type: 6, scale: 10, offset: 0
25
26
  )
@@ -42,7 +43,7 @@ describe FitParser::File::Data do
42
43
  it 'reads the entire record' do
43
44
  # read first the record definition
44
45
  expect(@result.raw_field_array).to be == [123_456_789, 987_654_321]
45
- expect(@result.raw_field_4).to be == [1, 3]
46
+ expect(@result.raw_time_mode).to be == [1, 3]
46
47
  expect(@result.raw_field_8).to be == 1539
47
48
  expect(@result.raw_active_time_zone).to be == 0
48
49
  end
@@ -53,8 +54,8 @@ describe FitParser::File::Data do
53
54
  end
54
55
 
55
56
  it 'does not apply the scale equal to 1 for arrays' do
56
- expect(@result.raw_field_4).to be == [1, 3]
57
- expect(@result.field_4.to_s).to be_eql('[1, 3]')
57
+ expect(@result.raw_time_mode).to be == [1, 3]
58
+ expect(@result.time_mode.to_s).to be_eql('[1, 3]')
58
59
  end
59
60
 
60
61
  it 'does apply scale on each element of an array' do
@@ -4,7 +4,7 @@ describe FitParser::File::Record do
4
4
  describe '#read' do
5
5
  context 'given a sample definition record' do
6
6
  it 'works' do
7
- record = described_class.new({})
7
+ record = described_class.new({}, {})
8
8
  file = example_file('record/definition_record')
9
9
  record.read(file)
10
10
  expect(record.header).to be_a(FitParser::File::RecordHeader)
@@ -15,11 +15,11 @@ describe FitParser::File::Record do
15
15
  context 'given a sample data record with a string non null terminated' do
16
16
  context 'string length is equal to field size' do
17
17
  it 'works' do
18
- record = described_class.new({})
18
+ record = described_class.new({}, {})
19
19
  record.read(example_file('record/definition_record_2.fit'))
20
20
  definitions = record.definitions
21
21
  file = example_file('record/data_record_2.fit')
22
- record = described_class.new(definitions).read(file)
22
+ record = described_class.new(definitions, {}).read(file)
23
23
  expect(record.header).to be_a(FitParser::File::RecordHeader)
24
24
  expect(record.content.raw_version).to eql(250)
25
25
  expect(record.content.raw_part_number).to eql('123-A1234-00')
@@ -28,11 +28,11 @@ describe FitParser::File::Record do
28
28
 
29
29
  context 'string length is smaller than field size' do
30
30
  it 'works' do
31
- record = described_class.new({})
31
+ record = described_class.new({}, {})
32
32
  record.read(example_file('record/definition_record_2.fit'))
33
33
  definitions = record.definitions
34
34
  file = example_file('record/data_record_2bis.fit')
35
- record = described_class.new(definitions).read(file)
35
+ record = described_class.new(definitions, {}).read(file)
36
36
  expect(record.header).to be_a(FitParser::File::RecordHeader)
37
37
  expect(record.content.raw_version).to eql(251)
38
38
  expect(record.content.version).to eql(2.51)
@@ -40,4 +40,30 @@ describe FitParser do
40
40
  data = FitParser.load_file(path)
41
41
  expect(data.records).to_not be_nil
42
42
  end
43
+
44
+ context 'with IQ datafields' do
45
+ it 'works 1375670253.fit' do
46
+ path = 'spec/support/examples/1375670253.fit'
47
+ data = FitParser.load_file(path)
48
+ expect(data.records).to_not be_nil
49
+ end
50
+
51
+ it 'works 1379311720.fit' do
52
+ path = 'spec/support/examples/1379311720.fit'
53
+ data = FitParser.load_file(path)
54
+ expect(data.records).to_not be_nil
55
+ end
56
+
57
+ it 'works 6AUI5200.FIT' do
58
+ path = 'spec/support/examples/6AUI5200.fit'
59
+ data = FitParser.load_file(path)
60
+ expect(data.records).to_not be_nil
61
+ end
62
+
63
+ it 'works 1426768070-2.fit' do
64
+ path = 'spec/support/examples/1426768070-2.fit'
65
+ data = FitParser.load_file(path)
66
+ expect(data.records).to_not be_nil
67
+ end
68
+ end
43
69
  end
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fit_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dima Mescheryakov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-11 00:00:00.000000000 Z
11
+ date: 2016-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bindata
@@ -143,6 +143,7 @@ executables: []
143
143
  extensions: []
144
144
  extra_rdoc_files: []
145
145
  files:
146
+ - lib/bindata/dsl_field_validator.rb
146
147
  - lib/fit_parser.rb
147
148
  - lib/fit_parser/file.rb
148
149
  - lib/fit_parser/file/data.rb
@@ -165,6 +166,10 @@ files:
165
166
  - spec/file_spec.rb
166
167
  - spec/fit_parser_spec.rb
167
168
  - spec/spec_helper.rb
169
+ - spec/support/examples/1375670253.fit
170
+ - spec/support/examples/1379311720.fit
171
+ - spec/support/examples/1426768070-2.fit
172
+ - spec/support/examples/6AUI5200.FIT
168
173
  - spec/support/examples/file/3110334490
169
174
  - spec/support/examples/file/3863374146
170
175
  - spec/support/examples/file/be470628-c34a-4189-aae3-42bef36436ce.fit