fit_parser 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/fit_parser/file/data.rb +33 -36
- data/lib/fit_parser/file/definition.rb +10 -13
- data/lib/fit_parser/file/definitions.rb +588 -588
- data/lib/fit_parser/file/record.rb +6 -19
- data/lib/fit_parser/file/type.rb +12 -11
- data/lib/fit_parser/file/types.rb +84 -84
- data/lib/fit_parser/file.rb +4 -8
- data/lib/fit_parser/version.rb +1 -1
- data/lib/fit_parser.rb +1 -1
- data/spec/file/data_spec.rb +43 -25
- data/spec/file/definition_spec.rb +2 -2
- data/spec/file/definitions_spec.rb +21 -21
- data/spec/file/header_spec.rb +6 -6
- data/spec/file/record_header_spec.rb +2 -2
- data/spec/file/record_spec.rb +33 -44
- data/spec/file/type_spec.rb +15 -11
- data/spec/file/types_spec.rb +21 -17
- data/spec/fit_parser_spec.rb +14 -1
- data/spec/support/examples/file/3110334490 +0 -0
- data/spec/support/examples/file/3863374146 +0 -0
- metadata +26 -43
- data/.document +0 -5
- data/.rspec +0 -2
- data/Gemfile +0 -15
- data/Gemfile.lock +0 -105
- data/README.md +0 -11
- data/Rakefile +0 -38
data/spec/file/data_spec.rb
CHANGED
@@ -1,16 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe FitParser::File::Data do
|
4
|
-
describe
|
4
|
+
describe '.generate' do
|
5
5
|
context 'standard definition' do
|
6
6
|
let(:definition) do
|
7
|
-
FitParser::File::Definition.read
|
7
|
+
FitParser::File::Definition.read(
|
8
|
+
example_file('record/message/definition')
|
9
|
+
)
|
8
10
|
end
|
9
11
|
|
10
12
|
subject { described_class.generate(definition) }
|
11
13
|
|
12
14
|
its(:ancestors) { should include(BinData::Record) }
|
13
|
-
its(
|
15
|
+
its('new.record_type') { should eq(:file_id) }
|
14
16
|
end
|
15
17
|
|
16
18
|
context 'definition with multiple time the same field' do
|
@@ -18,7 +20,9 @@ describe FitParser::File::Data do
|
|
18
20
|
@fields = FitParser::File::Definitions.fields
|
19
21
|
@dyn_fields = FitParser::File::Definitions.dyn_fields
|
20
22
|
# force a fake definition for scaling of arrays
|
21
|
-
FitParser::File::Definitions.add_field
|
23
|
+
FitParser::File::Definitions.add_field(
|
24
|
+
2, 2, 'field_array', type: 6, scale: 10, offset: 0
|
25
|
+
)
|
22
26
|
end
|
23
27
|
|
24
28
|
after :all do
|
@@ -29,30 +33,32 @@ describe FitParser::File::Data do
|
|
29
33
|
before :each do
|
30
34
|
def_file = example_file('record/message/definition_field_array.fit')
|
31
35
|
data_file = example_file('record/message/data_field_array.fit')
|
32
|
-
definition = described_class.generate(
|
33
|
-
|
36
|
+
definition = described_class.generate(
|
37
|
+
FitParser::File::Definition.read(def_file)
|
38
|
+
)
|
39
|
+
@result = definition.read(data_file)
|
34
40
|
end
|
35
41
|
|
36
|
-
it
|
42
|
+
it 'reads the entire record' do
|
37
43
|
# read first the record definition
|
38
|
-
expect(@result.raw_field_array).to be == [
|
39
|
-
expect(@result.raw_field_4).to be == [
|
44
|
+
expect(@result.raw_field_array).to be == [123_456_789, 987_654_321]
|
45
|
+
expect(@result.raw_field_4).to be == [1, 3]
|
40
46
|
expect(@result.raw_field_8).to be == 1539
|
41
47
|
expect(@result.raw_active_time_zone).to be == 0
|
42
48
|
end
|
43
|
-
|
44
|
-
it
|
49
|
+
|
50
|
+
it 'does not apply the scale equal to 1 for integer' do
|
45
51
|
expect(@result.raw_active_time_zone).to be == 0
|
46
52
|
expect(@result.active_time_zone.to_s).to be_eql '0'
|
47
53
|
end
|
48
|
-
|
49
|
-
it
|
50
|
-
expect(@result.raw_field_4).to be == [
|
51
|
-
expect(@result.field_4.to_s).to be_eql
|
54
|
+
|
55
|
+
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]')
|
52
58
|
end
|
53
59
|
|
54
|
-
it
|
55
|
-
expect(@result.raw_field_array).to be == [
|
60
|
+
it 'does apply scale on each element of an array' do
|
61
|
+
expect(@result.raw_field_array).to be == [123_456_789, 987_654_321]
|
56
62
|
expect(@result.field_array.to_s).to be_eql '[12345678.9, 98765432.1]'
|
57
63
|
end
|
58
64
|
end
|
@@ -61,8 +67,10 @@ describe FitParser::File::Data do
|
|
61
67
|
before :each do
|
62
68
|
def_file = example_file('record/message/definition_dynamic_fields.fit')
|
63
69
|
data_file = example_file('record/message/data_dynamic_fields.fit')
|
64
|
-
definition = described_class.generate(
|
65
|
-
|
70
|
+
definition = described_class.generate(
|
71
|
+
FitParser::File::Definition.read(def_file)
|
72
|
+
)
|
73
|
+
@result = definition.read(data_file)
|
66
74
|
end
|
67
75
|
|
68
76
|
it 'uses dynamic field value' do
|
@@ -75,8 +83,10 @@ describe FitParser::File::Data do
|
|
75
83
|
before :each do
|
76
84
|
def_file = example_file('record/message/definition_dynamic_fields.fit')
|
77
85
|
data_file = example_file('record/message/data_dynamic_fields.fit')
|
78
|
-
definition = described_class.generate(
|
79
|
-
|
86
|
+
definition = described_class.generate(
|
87
|
+
FitParser::File::Definition.read(def_file)
|
88
|
+
)
|
89
|
+
@result = definition.read(data_file)
|
80
90
|
end
|
81
91
|
|
82
92
|
it 'returns the real value' do
|
@@ -87,13 +97,19 @@ describe FitParser::File::Data do
|
|
87
97
|
|
88
98
|
context 'definition with bit field types' do
|
89
99
|
before :each do
|
90
|
-
def_file = example_file(
|
91
|
-
|
100
|
+
def_file = example_file(
|
101
|
+
'record/message/definition_file_capabilities.fit'
|
102
|
+
)
|
103
|
+
@definition = described_class.generate(
|
104
|
+
FitParser::File::Definition.read(def_file)
|
105
|
+
)
|
92
106
|
end
|
93
107
|
|
94
108
|
context 'when only 1 bit set' do
|
95
109
|
it 'returns the single value' do
|
96
|
-
res = @definition.read(
|
110
|
+
res = @definition.read(
|
111
|
+
example_file('record/message/data_file_capabilities_activities.fit')
|
112
|
+
)
|
97
113
|
expect(res.raw_flags).to eq(2)
|
98
114
|
expect(res.flags).to eq('read')
|
99
115
|
end
|
@@ -101,7 +117,9 @@ describe FitParser::File::Data do
|
|
101
117
|
|
102
118
|
context 'when several bits set' do
|
103
119
|
it 'returns the compound value' do
|
104
|
-
res = @definition.read(
|
120
|
+
res = @definition.read(
|
121
|
+
example_file('record/message/data_file_capabilities_settings.fit')
|
122
|
+
)
|
105
123
|
expect(res.raw_flags).to eq(6)
|
106
124
|
expect(res.flags).to eq('read/write')
|
107
125
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe FitParser::File::Definition do
|
4
|
-
context
|
5
|
-
describe
|
4
|
+
context 'given a sample definition message' do
|
5
|
+
describe '.read' do
|
6
6
|
subject do
|
7
7
|
described_class.read example_file('record/message/definition')
|
8
8
|
end
|
@@ -4,7 +4,7 @@ require 'spec_helper'
|
|
4
4
|
# with already defined fields in definitions.rb and test are
|
5
5
|
# not really independant of the code
|
6
6
|
describe FitParser::File::Definitions do
|
7
|
-
describe
|
7
|
+
describe '.add_field' do
|
8
8
|
before :all do
|
9
9
|
@fields = described_class.fields
|
10
10
|
@dyn_fields = described_class.dyn_fields
|
@@ -15,16 +15,16 @@ describe FitParser::File::Definitions do
|
|
15
15
|
FitParser::File::Definitions.dyn_fields = @dyn_fields
|
16
16
|
end
|
17
17
|
|
18
|
-
context
|
18
|
+
context 'without additional options' do
|
19
19
|
before :each do
|
20
20
|
FitParser::File::Definitions.fields = Hash.new { |h,k| h[k]={} }
|
21
21
|
FitParser::File::Definitions.dyn_fields = Hash.new { |h,k| h[k]={} }
|
22
22
|
described_class.add_field(999, 999, 'rspec_test')
|
23
23
|
end
|
24
24
|
|
25
|
-
it
|
26
|
-
expect(described_class.get_field(999,999)).to be_a(Hash)
|
27
|
-
expect(described_class.get_field(999,999)).to eql(
|
25
|
+
it 'adds field data' do
|
26
|
+
expect(described_class.get_field(999, 999)).to be_a(Hash)
|
27
|
+
expect(described_class.get_field(999, 999)).to eql(name: 'rspec_test')
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'raised an error for dynamic field data' do
|
@@ -32,29 +32,29 @@ describe FitParser::File::Definitions do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
context
|
35
|
+
context 'with additional options' do
|
36
36
|
before :each do
|
37
|
-
FitParser::File::Definitions.fields = Hash.new { |h,k| h[k]={} }
|
38
|
-
FitParser::File::Definitions.dyn_fields = Hash.new { |h,k| h[k]={} }
|
39
|
-
described_class.add_field(999, 999, 'rspec_test', :
|
40
|
-
described_class.add_field(999, 999, 'rspec_test_dyn', :
|
37
|
+
FitParser::File::Definitions.fields = Hash.new { |h, k| h[k] = {} }
|
38
|
+
FitParser::File::Definitions.dyn_fields = Hash.new { |h, k| h[k] = {} }
|
39
|
+
described_class.add_field(999, 999, 'rspec_test', scale: 100, units: 'm')
|
40
|
+
described_class.add_field(999, 999, 'rspec_test_dyn', type: 4, scale: 10, offset: 10, ref_field_name: nil, ref_field_values: nil)
|
41
41
|
end
|
42
42
|
|
43
|
-
it
|
43
|
+
it 'adds field data' do
|
44
44
|
expect(described_class.get_field(999, 999)).to be_a(Hash)
|
45
|
-
expect(described_class.get_field(999, 999)).to eql(
|
45
|
+
expect(described_class.get_field(999, 999)).to eql(name: 'rspec_test', scale: 100, units: 'm')
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
it 'adds dynamic field data' do
|
49
49
|
expect(described_class.get_dynamic_fields(999, 999)).to be_a(Hash)
|
50
|
-
expect(described_class.get_dynamic_fields(999, 999)).to eql(
|
50
|
+
expect(described_class.get_dynamic_fields(999, 999)).to eql(rspec_test_dyn: { type: 4, scale: 10, offset: 10, ref_field_name: nil, ref_field_values: nil })
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
describe
|
56
|
-
it
|
57
|
-
expect(described_class.get_field(100,101)).to be_nil
|
55
|
+
describe '.get_field' do
|
56
|
+
it 'returns nil if no field exists' do
|
57
|
+
expect(described_class.get_field(100, 101)).to be_nil
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
@@ -65,15 +65,15 @@ describe FitParser::File::Definitions do
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
-
describe
|
69
|
-
it
|
68
|
+
describe '.add_name' do
|
69
|
+
it 'adds a name' do
|
70
70
|
described_class.add_name(20, 'record')
|
71
71
|
expect(described_class.get_name(20)).to eql('record')
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
describe
|
76
|
-
it
|
75
|
+
describe '.get_name' do
|
76
|
+
it 'returns nil if no name exists' do
|
77
77
|
expect(described_class.get_name(100)).to be_nil
|
78
78
|
end
|
79
79
|
end
|
data/spec/file/header_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe FitParser::File::Header do
|
4
|
-
context
|
4
|
+
context 'given a sample FIT header' do
|
5
5
|
subject do
|
6
6
|
described_class.read example_file('file/header')
|
7
7
|
end
|
@@ -9,11 +9,11 @@ describe FitParser::File::Header do
|
|
9
9
|
its(:header_size) { should == 12 }
|
10
10
|
its(:protocol_version) { should == 16 }
|
11
11
|
its(:profile_version) { should == 64 }
|
12
|
-
its(:data_size) { should ==
|
13
|
-
its(:data_type) { should ==
|
12
|
+
its(:data_size) { should == 36_069 }
|
13
|
+
its(:data_type) { should == '.FIT' }
|
14
14
|
end
|
15
15
|
|
16
|
-
context
|
16
|
+
context 'given a sample header file of 14 bytes length' do
|
17
17
|
subject do
|
18
18
|
described_class.read example_file('file/header_14b.fit')
|
19
19
|
end
|
@@ -22,7 +22,7 @@ describe FitParser::File::Header do
|
|
22
22
|
its(:protocol_version) { should == 16 }
|
23
23
|
its(:profile_version) { should == 411 }
|
24
24
|
its(:data_size) { should == 325 }
|
25
|
-
its(:data_type) { should ==
|
26
|
-
its(:crc) { should ==
|
25
|
+
its(:data_type) { should == '.FIT' }
|
26
|
+
its(:crc) { should == 17_101 }
|
27
27
|
end
|
28
28
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe FitParser::File::RecordHeader do
|
4
|
-
context
|
4
|
+
context 'given a sample normal header' do
|
5
5
|
subject do
|
6
6
|
described_class.read example_file('record/normal_header')
|
7
7
|
end
|
@@ -14,7 +14,7 @@ describe FitParser::File::RecordHeader do
|
|
14
14
|
it { is_expected.not_to be_a_compressed_timestamp }
|
15
15
|
end
|
16
16
|
|
17
|
-
context
|
17
|
+
context 'given a sample compressed timestamp header' do
|
18
18
|
# TODO
|
19
19
|
end
|
20
20
|
end
|
data/spec/file/record_spec.rb
CHANGED
@@ -1,56 +1,45 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe FitParser::File::Record do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
let(:file) { example_file('record/definition_record') }
|
14
|
-
|
15
|
-
it { expect(subject.header).to be_a FitParser::File::RecordHeader }
|
16
|
-
it { expect(subject.content).to be_a FitParser::File::Definition }
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
context "given a sample data record" do
|
21
|
-
let(:file) { nil }
|
4
|
+
describe '#read' do
|
5
|
+
context 'given a sample definition record' do
|
6
|
+
it 'works' do
|
7
|
+
record = described_class.new({})
|
8
|
+
file = example_file('record/definition_record')
|
9
|
+
record.read(file)
|
10
|
+
expect(record.header).to be_a(FitParser::File::RecordHeader)
|
11
|
+
expect(record.content).to be_a(FitParser::File::Definition)
|
12
|
+
end
|
22
13
|
end
|
23
|
-
|
24
|
-
context "given a sample data record with a string non null terminated" do
|
25
14
|
|
15
|
+
context 'given a sample data record with a string non null terminated' do
|
26
16
|
context 'string length is equal to field size' do
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
17
|
+
it 'works' do
|
18
|
+
record = described_class.new({})
|
19
|
+
record.read(example_file('record/definition_record_2.fit'))
|
20
|
+
definitions = record.definitions
|
21
|
+
file = example_file('record/data_record_2.fit')
|
22
|
+
record = described_class.new(definitions).read(file)
|
23
|
+
expect(record.header).to be_a(FitParser::File::RecordHeader)
|
24
|
+
expect(record.content.raw_version).to eql(250)
|
25
|
+
expect(record.content.raw_part_number).to eql('123-A1234-00')
|
26
|
+
end
|
33
27
|
end
|
34
28
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
29
|
+
context 'string length is smaller than field size' do
|
30
|
+
it 'works' do
|
31
|
+
record = described_class.new({})
|
32
|
+
record.read(example_file('record/definition_record_2.fit'))
|
33
|
+
definitions = record.definitions
|
34
|
+
file = example_file('record/data_record_2bis.fit')
|
35
|
+
record = described_class.new(definitions).read(file)
|
36
|
+
expect(record.header).to be_a(FitParser::File::RecordHeader)
|
37
|
+
expect(record.content.raw_version).to eql(251)
|
38
|
+
expect(record.content.version).to eql(2.51)
|
39
|
+
expect(record.content.raw_part_number).to eql('123-A1234')
|
40
|
+
expect(record.content.part_number).to eql('123-A1234')
|
41
|
+
end
|
44
42
|
end
|
45
43
|
end
|
46
44
|
end
|
47
|
-
|
48
|
-
describe ".clear_definitions" do
|
49
|
-
it "should clear the definitions class variable" do
|
50
|
-
described_class.read example_file('record/definition_record')
|
51
|
-
expect(described_class.definitions).to_not be_empty
|
52
|
-
described_class.clear_definitions!
|
53
|
-
expect(described_class.definitions).to be_empty
|
54
|
-
end
|
55
|
-
end
|
56
45
|
end
|
data/spec/file/type_spec.rb
CHANGED
@@ -4,7 +4,11 @@ describe FitParser::File::Type do
|
|
4
4
|
before :all do
|
5
5
|
@types = FitParser::File::Types.types
|
6
6
|
FitParser::File::Types.add_type(:int_type, :sint8)
|
7
|
-
FitParser::File::Types.add_type(
|
7
|
+
FitParser::File::Types.add_type(
|
8
|
+
:int_type_with_val,
|
9
|
+
:uint8,
|
10
|
+
values: { 1 => 'one', 2 => 'two', 3 => 'three' }
|
11
|
+
)
|
8
12
|
end
|
9
13
|
|
10
14
|
after :all do
|
@@ -14,11 +18,13 @@ describe FitParser::File::Type do
|
|
14
18
|
describe '.get_type' do
|
15
19
|
context 'when valid name' do
|
16
20
|
it 'returns a type' do
|
17
|
-
expect(described_class.get_type(:int_type))
|
21
|
+
expect(described_class.get_type(:int_type))
|
22
|
+
.to be_a(FitParser::File::Type)
|
18
23
|
end
|
19
24
|
|
20
25
|
it 'returns always the same instance' do
|
21
|
-
expect(described_class.get_type(:int_type))
|
26
|
+
expect(described_class.get_type(:int_type))
|
27
|
+
.to eql(described_class.get_type(:int_type))
|
22
28
|
end
|
23
29
|
end
|
24
30
|
|
@@ -31,7 +37,6 @@ describe FitParser::File::Type do
|
|
31
37
|
|
32
38
|
describe '#value' do
|
33
39
|
context 'when type has values' do
|
34
|
-
|
35
40
|
let(:type) { described_class.get_type(:int_type_with_val) }
|
36
41
|
|
37
42
|
context 'known value requested' do
|
@@ -39,7 +44,7 @@ describe FitParser::File::Type do
|
|
39
44
|
expect(type.value(2)).to eql 'two'
|
40
45
|
end
|
41
46
|
end
|
42
|
-
|
47
|
+
|
43
48
|
context 'unknown value requested' do
|
44
49
|
it 'returns the input value' do
|
45
50
|
expect(type.value(999)).to eql 999
|
@@ -57,19 +62,18 @@ describe FitParser::File::Type do
|
|
57
62
|
context 'when type has date_time value' do
|
58
63
|
let(:type) { described_class.get_type(:date_time) }
|
59
64
|
it 'returns the date' do
|
60
|
-
expect(type.value(
|
65
|
+
expect(type.value(790_509_304)).to eq('2015-01-18 09:55:04 UTC')
|
61
66
|
end
|
62
67
|
end
|
63
68
|
|
64
69
|
context 'when type has message_index value' do
|
65
70
|
let(:type) { described_class.get_type(:message_index) }
|
66
|
-
|
71
|
+
|
67
72
|
it 'returns the message_index' do
|
68
73
|
expect(type.value(10)).to eq(10)
|
69
|
-
expect(type.value(
|
70
|
-
expect(type.value(
|
71
|
-
end
|
72
|
-
|
74
|
+
expect(type.value(32_778)).to eq(10)
|
75
|
+
expect(type.value(28_682)).to eq(10)
|
76
|
+
end
|
73
77
|
end
|
74
78
|
|
75
79
|
context 'when type has file_flags value' do
|
data/spec/file/types_spec.rb
CHANGED
@@ -11,14 +11,15 @@ describe FitParser::File::Types do
|
|
11
11
|
|
12
12
|
describe '.add_type' do
|
13
13
|
before :each do
|
14
|
-
FitParser::File::Types.types = Hash.new { |h,k| h[k]={} }
|
14
|
+
FitParser::File::Types.types = Hash.new { |h, k| h[k] = {} }
|
15
15
|
end
|
16
16
|
|
17
17
|
context 'for enum type' do
|
18
18
|
it 'add enum data' do
|
19
|
-
val = {:
|
19
|
+
val = { values: { 1 => 'val1', 2 => 'val2', 3 => 'val3' } }
|
20
20
|
described_class.add_type(:test_enum, :enum, val)
|
21
|
-
expect(described_class.get_type_definition(:test_enum))
|
21
|
+
expect(described_class.get_type_definition(:test_enum))
|
22
|
+
.to eql(val.merge(basic_type: :enum))
|
22
23
|
end
|
23
24
|
end
|
24
25
|
end
|
@@ -28,34 +29,40 @@ describe FitParser::File::Types do
|
|
28
29
|
expect(described_class.get_type_definition(:rspec_unknown)).to be_nil
|
29
30
|
end
|
30
31
|
end
|
31
|
-
|
32
|
+
|
32
33
|
describe '.date_time_value' do
|
33
34
|
context 'wen value below min' do
|
34
35
|
it 'returns system time in second' do
|
35
|
-
|
36
|
-
expect(described_class.date_time_value(
|
36
|
+
values = [9999, { 268_435_456 => 'min' }, utc: true]
|
37
|
+
expect(described_class.date_time_value(*values)).to eql('9999')
|
38
|
+
values = [9999, { 268_435_456 => 'min' }, utc: false]
|
39
|
+
expect(described_class.date_time_value(*values)).to eql('9999')
|
37
40
|
end
|
38
41
|
end
|
39
42
|
|
40
43
|
context 'when value is above min' do
|
41
44
|
context 'with UTC mode' do
|
42
45
|
it 'returns exact date UTC' do
|
43
|
-
|
46
|
+
values = [790_509_304, { 268_435_456 => 'min' }, utc: true]
|
47
|
+
expect(described_class.date_time_value(*values))
|
48
|
+
.to eql('2015-01-18 09:55:04 UTC')
|
44
49
|
end
|
45
50
|
end
|
46
|
-
|
51
|
+
|
47
52
|
context 'with local mode' do
|
48
53
|
it 'returns exact date in locale time zone' do
|
49
54
|
# TODO: manage answer based on current system local
|
50
|
-
|
55
|
+
values = [790_509_304, { 268_435_456 => 'min' }, utc: false]
|
56
|
+
expect(described_class.date_time_value(*values)).not_to match(/UTC$/)
|
51
57
|
end
|
52
58
|
end
|
53
|
-
|
54
59
|
end
|
55
60
|
end
|
56
61
|
|
57
62
|
describe '.message_index_value' do
|
58
|
-
let(:values)
|
63
|
+
let(:values) do
|
64
|
+
{ 32_768 => 'selected', 28_672 => 'reserved', 4095 => 'mask' }
|
65
|
+
end
|
59
66
|
|
60
67
|
context 'when value is not reserved or selected' do
|
61
68
|
it 'returns the message index' do
|
@@ -65,20 +72,19 @@ describe FitParser::File::Types do
|
|
65
72
|
|
66
73
|
context 'when value is reserved' do
|
67
74
|
it 'returns real message index' do
|
68
|
-
expect(described_class.message_index_value(
|
75
|
+
expect(described_class.message_index_value(28_682, values)).to eq(10)
|
69
76
|
end
|
70
77
|
end
|
71
78
|
|
72
79
|
context 'when value is selected' do
|
73
80
|
it 'returns real message index' do
|
74
|
-
expect(described_class.message_index_value(
|
81
|
+
expect(described_class.message_index_value(32_778, values)).to eq(10)
|
75
82
|
end
|
76
83
|
end
|
77
|
-
|
78
84
|
end
|
79
85
|
|
80
86
|
describe '.bitfield_value' do
|
81
|
-
let(:values) { {0x02 => 'read', 0x04 => 'write', 0x08 => 'erase'} }
|
87
|
+
let(:values) { { 0x02 => 'read', 0x04 => 'write', 0x08 => 'erase' } }
|
82
88
|
|
83
89
|
context 'when value is a single bit' do
|
84
90
|
it 'returns the single value' do
|
@@ -95,6 +101,4 @@ describe FitParser::File::Types do
|
|
95
101
|
end
|
96
102
|
end
|
97
103
|
end
|
98
|
-
|
99
104
|
end
|
100
|
-
|
data/spec/fit_parser_spec.rb
CHANGED
@@ -1,10 +1,23 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe FitParser do
|
4
|
-
describe
|
4
|
+
describe 'VERSION' do
|
5
5
|
subject{ FitParser::VERSION }
|
6
6
|
|
7
7
|
it { is_expected.to be_a(String) }
|
8
8
|
it { is_expected.to match(/\d{1,2}\.\d{1,2}\.\d{1,2}/) }
|
9
9
|
end
|
10
|
+
|
11
|
+
describe '.load_file' do
|
12
|
+
it 'works with threads' do
|
13
|
+
threads = []
|
14
|
+
%w(3863374146 3110334490).each do |file|
|
15
|
+
threads << Thread.new(file) do |el|
|
16
|
+
data = FitParser.load_file("spec/support/examples/file/#{el}")
|
17
|
+
expect(data.records).to_not be_nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
threads.each { |thread| thread.join }
|
21
|
+
end
|
22
|
+
end
|
10
23
|
end
|
Binary file
|
Binary file
|