fit_parser 0.0.4 → 0.0.5

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: db4819e337a07b93ef7ca45b6cfcea751d36b309
4
- data.tar.gz: 106c81aefce23476ba864dd51cbd4251678ae441
3
+ metadata.gz: cfe16c1aae89815b69c6e91a5fdc5da00755a8a3
4
+ data.tar.gz: 37f28492ce843593331c48abd109359e80b290a0
5
5
  SHA512:
6
- metadata.gz: a796b10d34467bec83a8670c08ded3e04844beafa96867ebb760ea38b6374dd4f21bf878cccb96bec8e6ef3afa8710b4d89f0a2827b8949f44f8a7d1589800b7
7
- data.tar.gz: 9fa814a4fe95261918511cfc22b045146846a5912892965998653af19c53656eb9b528624b7a9cdc83db92ee0512a6794248787df2b793433346ea852342dcb6
6
+ metadata.gz: 8e6191854d0c785710063ca83ec4d4fda9fc0f2e39a4dde31a85595f2678037ef4a3d8fcfebcb175f97074207cff27ab86a521be9ee827847b138fb29200dcb9
7
+ data.tar.gz: 07caf2f96cde4c0f98386267cd4199f0c7c6a661794db9e51e7e76838f19bdf01753f8b31c26ea5e4e10b35e46e20c26678e054baed82a948920c14ab3afd395
data/.rspec CHANGED
@@ -1 +1,2 @@
1
1
  --color
2
+ --format documentation
data/README.md CHANGED
@@ -1,27 +1,11 @@
1
- # fit
2
-
3
- A ruby gem for parsing [fit files](http://www.thisisant.com/pages/products/fit-sdk). It makes heavy use of the [bindata gem](http://bindata.rubyforge.org/).
1
+ # FitParser
4
2
 
5
3
  ## Example usage
6
4
 
7
5
  ```ruby
8
- require 'fit'
6
+ require 'fit_parser'
9
7
 
10
- fit_file = Fit.load_file(ARGV[0])
8
+ fit_file = FitParser.load_file(ARGV[0])
11
9
 
12
10
  records = fit_file.records.select{ |r| r.content.record_type != :definition }.map{ |r| r.content }
13
11
  ```
14
-
15
- ## Contributing to fit
16
-
17
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
18
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
19
- * Fork the project
20
- * Start a feature/bugfix branch
21
- * Commit and push until you are happy with your contribution
22
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
23
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
24
-
25
- ## Copyright
26
-
27
- Copyright (c) 2011 Jeff Wallace. See LICENSE.txt for further details.
@@ -1,46 +1,62 @@
1
1
  module FitParser
2
2
  class File
3
3
  module Definitions
4
+ def self.fields
5
+ @fields ||= Hash.new { |h, k| h[k]= {} }
6
+ end
4
7
 
5
- @@fields = Hash.new{ |h,k| h[k]= {} }
6
- @@dyn_fields = Hash.new{ |h,k| h[k]= {} }
7
- @@names = Hash.new
8
-
9
- class << self
10
- def add_field(global_msg_num, field_def_num, name, options = {})
11
- if @@fields[global_msg_num].has_key? field_def_num
12
- raise "bad definition of dynamic field (#{name}) without :ref_field_name or :ref_field_values" unless options.has_key?(:ref_field_name) && options.has_key?(:ref_field_values)
13
- @@dyn_fields[global_msg_num][field_def_num] ||= {}
14
- @@dyn_fields[global_msg_num][field_def_num][name.to_sym] = options
15
- # let's put the ref_field_values with the raw_value instead of the real value
16
- type = Types.get_type_definition(options[:ref_field_name].to_sym) if options[:ref_field_name]
17
- # basic types are not found and returns nil (also some rspec dummy tests)
18
- if type
19
- type = type[:values].invert
20
- @@dyn_fields[global_msg_num][field_def_num][name.to_sym][:ref_field_values] = options[:ref_field_values].map { |elt| type[elt.to_s] }
21
- end
22
- else
23
- @@fields[global_msg_num][field_def_num] = options.merge(:name => name)
24
- end
25
- end
8
+ def self.fields=(value)
9
+ @fields = value
10
+ end
26
11
 
27
- def get_field(global_msg_num, field_def_num)
28
- @@fields[global_msg_num][field_def_num]
29
- end
12
+ def self.dyn_fields
13
+ @dyn_fields ||= Hash.new { |h, k| h[k]= {} }
14
+ end
30
15
 
31
- def get_dynamic_fields(global_msg_num, field_def_num)
32
- @@dyn_fields[global_msg_num][field_def_num]
33
- end
16
+ def self.dyn_fields=(value)
17
+ @dyn_fields = value
18
+ end
34
19
 
35
- def add_name(global_msg_num, name)
36
- @@names[global_msg_num] = name
37
- end
20
+ def self.names
21
+ @names ||= Hash.new
22
+ end
38
23
 
39
- def get_name(global_msg_num)
40
- @@names[global_msg_num]
24
+ def self.names=(value)
25
+ @names = value
26
+ end
27
+
28
+ def self.add_field(global_msg_num, field_def_num, name, options = {})
29
+ if Definitions.fields[global_msg_num].has_key? field_def_num
30
+ raise "bad definition of dynamic field (#{name}) without :ref_field_name or :ref_field_values" unless options.has_key?(:ref_field_name) && options.has_key?(:ref_field_values)
31
+ Definitions.dyn_fields[global_msg_num][field_def_num] ||= {}
32
+ Definitions.dyn_fields[global_msg_num][field_def_num][name.to_sym] = options
33
+ # let's put the ref_field_values with the raw_value instead of the real value
34
+ type = Types.get_type_definition(options[:ref_field_name].to_sym) if options[:ref_field_name]
35
+ # basic types are not found and returns nil (also some rspec dummy tests)
36
+ if type
37
+ type = type[:values].invert
38
+ Definitions.dyn_fields[global_msg_num][field_def_num][name.to_sym][:ref_field_values] = options[:ref_field_values].map { |elt| type[elt.to_s] }
39
+ end
40
+ else
41
+ Definitions.fields[global_msg_num][field_def_num] = options.merge(:name => name)
41
42
  end
42
43
  end
43
44
 
45
+ def self.get_field(global_msg_num, field_def_num)
46
+ Definitions.fields[global_msg_num][field_def_num]
47
+ end
48
+
49
+ def self.get_dynamic_fields(global_msg_num, field_def_num)
50
+ Definitions.dyn_fields[global_msg_num][field_def_num]
51
+ end
52
+
53
+ def self.add_name(global_msg_num, name)
54
+ Definitions.names[global_msg_num] = name
55
+ end
56
+
57
+ def self.get_name(global_msg_num)
58
+ Definitions.names[global_msg_num]
59
+ end
44
60
  end
45
61
  end
46
62
  end
@@ -682,7 +698,7 @@ FitParser::File::Definitions.add_field 55, 5, 'activity_type', :type => :activit
682
698
  FitParser::File::Definitions.add_field 55, 6, 'activity_subtype', :type => :activity_subtype
683
699
  FitParser::File::Definitions.add_field 55, 7, 'activity_level', :type => :activity_level
684
700
  FitParser::File::Definitions.add_field 55, 8, 'distance_16', :type => :uint16, :unit => '100 * m'
685
- FitParser::File::Definitions.add_field 55, 9, 'cycles_16', :type => :uint16, :unit => '2 * cycles ', :unit => '(steps)'
701
+ FitParser::File::Definitions.add_field 55, 9, 'cycles_16', :type => :uint16, :unit => '(steps)'
686
702
  FitParser::File::Definitions.add_field 55, 10, 'active_time_16', :type => :uint16, :unit => 's'
687
703
  FitParser::File::Definitions.add_field 55, 11, 'local_timestamp', :type => :local_date_time
688
704
  FitParser::File::Definitions.add_field 55, 12, 'temperature', :type => :sint16, :scale => 100, :unit => 'C'
@@ -1,16 +1,20 @@
1
1
  module FitParser
2
2
  class File
3
3
  class Record
4
-
5
- @@definitions = {}
6
- mattr_reader :definitions, instance_reader: false
7
-
8
4
  def self.read(io)
9
5
  new.read(io)
10
6
  end
11
7
 
12
8
  def self.clear_definitions!
13
- @@definitions.clear
9
+ @definitions = {}
10
+ end
11
+
12
+ def self.definitions=(value)
13
+ @definitions = value
14
+ end
15
+
16
+ def self.definitions
17
+ @definitions
14
18
  end
15
19
 
16
20
  attr_reader :header, :content
@@ -21,10 +25,10 @@ module FitParser
21
25
  @content = case @header.message_type.snapshot
22
26
  when 1
23
27
  Definition.read(io).tap do |definition|
24
- @@definitions[@header.local_message_type.snapshot] = Data.generate(definition)
28
+ Record.definitions[@header.local_message_type.snapshot] = Data.generate(definition)
25
29
  end
26
30
  when 0
27
- definition = @@definitions[@header.local_message_type.snapshot]
31
+ definition = Record.definitions[@header.local_message_type.snapshot]
28
32
  raise "No definition for local message type: #{@header.local_message_type}" if definition.nil?
29
33
  definition.read(io)
30
34
  end
@@ -1,13 +1,18 @@
1
1
  module FitParser
2
2
  class File
3
3
  class Type
4
+ def self.types
5
+ @types ||= {}
6
+ end
4
7
 
5
- @@types = {}
8
+ def self.types=(value)
9
+ @types = value
10
+ end
6
11
 
7
12
  def self.get_type(name)
8
- return @@types[name] if @@types.has_key? name
13
+ return Type.types[name] if Type.types.has_key? name
9
14
  type = Types.get_type_definition name
10
- @@types[name] = type ? new(type) : nil
15
+ Type.types[name] = type ? new(type) : nil
11
16
  end
12
17
 
13
18
  def initialize(type)
@@ -1,46 +1,48 @@
1
1
  module FitParser
2
2
  class File
3
3
  module Types
4
+ def self.types=(value)
5
+ @types = value
6
+ end
4
7
 
5
- @@types = {}
8
+ def self.types
9
+ @types ||= {}
10
+ end
6
11
 
7
- class << self
8
- def add_type(name, type, option = {})
9
- @@types[name] = option.merge({:basic_type => type})
10
- end
12
+ def self.add_type(name, type, option = {})
13
+ Types.types[name] = option.merge(basic_type: type)
14
+ end
11
15
 
12
- def get_type_definition(name)
13
- return @@types[name] if @@types.has_key? name
14
- nil
15
- end
16
+ def self.get_type_definition(name)
17
+ return Types.types[name] if Types.types.has_key?(name)
18
+ nil
19
+ end
16
20
 
17
- def date_time_value(time, values, parameters)
18
- val = values.invert
19
- if time < val['min']
20
- time.to_s
21
- else
22
- res= parameters[:utc] ? Time.utc(1989,12,31) + time : Time.local(1989,12,31) + time
23
- res.to_s
24
- end
21
+ def self.date_time_value(time, values, parameters)
22
+ val = values.invert
23
+ if time < val['min']
24
+ time.to_s
25
+ else
26
+ res= parameters[:utc] ? Time.utc(1989, 12, 31) + time : Time.local(1989, 12, 31) + time
27
+ res.to_s
25
28
  end
29
+ end
26
30
 
27
- def message_index_value(msg_index, values, parameters = nil)
28
- val = values.invert
29
- msg_index & val['mask']
30
- end
31
+ def self.message_index_value(msg_index, values, parameters = nil)
32
+ val = values.invert
33
+ msg_index & val['mask']
34
+ end
31
35
 
32
- def bitfield_value(bitfield, values, parameters = nil)
33
- res = ''
34
- values.each do |key, val|
35
- if key & bitfield != 0
36
- res << '/' unless res.empty?
37
- res << val
38
- end
36
+ def self.bitfield_value(bitfield, values, parameters = nil)
37
+ res = ''
38
+ values.each do |key, val|
39
+ if key & bitfield != 0
40
+ res << '/' unless res.empty?
41
+ res << val
39
42
  end
40
- res
41
43
  end
44
+ res
42
45
  end
43
-
44
46
  end
45
47
  end
46
48
  end
@@ -1,3 +1,3 @@
1
1
  module FitParser
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
@@ -15,15 +15,15 @@ describe FitParser::File::Data do
15
15
 
16
16
  context 'definition with multiple time the same field' do
17
17
  before :all do
18
- @fields = FitParser::File::Definitions.class_variable_get :@@fields
19
- @dyn_fields = FitParser::File::Definitions.class_variable_get :@@dyn_fields
18
+ @fields = FitParser::File::Definitions.fields
19
+ @dyn_fields = FitParser::File::Definitions.dyn_fields
20
20
  # force a fake definition for scaling of arrays
21
21
  FitParser::File::Definitions.add_field 2, 2, "field_array", :type => 6, :scale => 10, :offset => 0
22
22
  end
23
23
 
24
24
  after :all do
25
- FitParser::File::Definitions.class_variable_set :@@fields, @fields
26
- FitParser::File::Definitions.class_variable_set :@@dyn_fields, @dyn_fields
25
+ FitParser::File::Definitions.fields = @fields
26
+ FitParser::File::Definitions.dyn_fields = @dyn_fields
27
27
  end
28
28
 
29
29
  before :each do
@@ -6,19 +6,19 @@ require 'spec_helper'
6
6
  describe FitParser::File::Definitions do
7
7
  describe ".add_field" do
8
8
  before :all do
9
- @fields = described_class.class_variable_get :@@fields
10
- @dyn_fields = described_class.class_variable_get :@@dyn_fields
9
+ @fields = described_class.fields
10
+ @dyn_fields = described_class.dyn_fields
11
11
  end
12
12
 
13
13
  after :all do
14
- FitParser::File::Definitions.class_variable_set(:@@fields, @fields)
15
- FitParser::File::Definitions.class_variable_set(:@@dyn_fields, @dyn_fields)
14
+ FitParser::File::Definitions.fields = @fields
15
+ FitParser::File::Definitions.dyn_fields = @dyn_fields
16
16
  end
17
17
 
18
18
  context "without additional options" do
19
19
  before :each do
20
- FitParser::File::Definitions.class_variable_set(:@@fields, Hash.new { |h,k| h[k]={} })
21
- FitParser::File::Definitions.class_variable_set(:@@dyn_fields, Hash.new { |h,k| h[k]={} })
20
+ FitParser::File::Definitions.fields = Hash.new { |h,k| h[k]={} }
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
 
@@ -34,9 +34,8 @@ describe FitParser::File::Definitions do
34
34
 
35
35
  context "with additional options" do
36
36
  before :each do
37
- FitParser::File::Definitions.class_variable_set(:@@fields, Hash.new { |h,k| h[k]={} })
38
- FitParser::File::Definitions.class_variable_set(:@@dyn_fields, Hash.new { |h,k| h[k]={} })
39
-
37
+ FitParser::File::Definitions.fields = Hash.new { |h,k| h[k]={} }
38
+ FitParser::File::Definitions.dyn_fields = Hash.new { |h,k| h[k]={} }
40
39
  described_class.add_field(999, 999, 'rspec_test', :scale => 100, :units => 'm')
41
40
  described_class.add_field(999, 999, 'rspec_test_dyn', :type => 4, :scale => 10, :offset => 10, :ref_field_name => nil, :ref_field_values => nil)
42
41
  end
@@ -55,7 +54,7 @@ describe FitParser::File::Definitions do
55
54
 
56
55
  describe ".get_field" do
57
56
  it "returns nil if no field exists" do
58
- expect(described_class.get_field(100,100)).to be_nil
57
+ expect(described_class.get_field(100,101)).to be_nil
59
58
  end
60
59
  end
61
60
 
@@ -2,26 +2,26 @@ require 'spec_helper'
2
2
 
3
3
  describe FitParser::File::Type do
4
4
  before :all do
5
- @types = FitParser::File::Types.class_variable_get :@@types
5
+ @types = FitParser::File::Types.types
6
6
  FitParser::File::Types.add_type(:int_type, :sint8)
7
7
  FitParser::File::Types.add_type(:int_type_with_val, :uint8, :values => {1 => 'one', 2 => 'two', 3 => 'three'})
8
8
  end
9
9
 
10
10
  after :all do
11
- FitParser::File::Types.class_variable_set(:@@types, @types)
11
+ FitParser::File::Types.types = @types
12
12
  end
13
13
 
14
14
  describe '.get_type' do
15
15
  context 'when valid name' do
16
16
  it 'returns a type' do
17
- expect(described_class.get_type(:int_type)).to be_a FitParser::File::Type
17
+ expect(described_class.get_type(:int_type)).to be_a(FitParser::File::Type)
18
18
  end
19
19
 
20
20
  it 'returns always the same instance' do
21
21
  expect(described_class.get_type(:int_type)).to equal described_class.get_type(:int_type)
22
22
  end
23
23
  end
24
-
24
+
25
25
  context 'when invalid name' do
26
26
  it 'returns nil' do
27
27
  expect(described_class.get_type(:unknown_type)).to be_nil
@@ -2,16 +2,16 @@ require 'spec_helper'
2
2
 
3
3
  describe FitParser::File::Types do
4
4
  before :all do
5
- @types = described_class.class_variable_get :@@types
5
+ @types = described_class.types
6
6
  end
7
7
 
8
8
  after :all do
9
- FitParser::File::Types.class_variable_set(:@@types, @types)
9
+ FitParser::File::Types.types = @types
10
10
  end
11
11
 
12
12
  describe '.add_type' do
13
13
  before :each do
14
- FitParser::File::Types.class_variable_set(:@@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
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.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dima Mescheryakov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-19 00:00:00.000000000 Z
11
+ date: 2016-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bindata
@@ -155,14 +155,12 @@ email: dima.mescheryakov@gmail.com
155
155
  executables: []
156
156
  extensions: []
157
157
  extra_rdoc_files:
158
- - LICENSE.txt
159
158
  - README.md
160
159
  files:
161
160
  - .document
162
161
  - .rspec
163
162
  - Gemfile
164
163
  - Gemfile.lock
165
- - LICENSE.txt
166
164
  - README.md
167
165
  - Rakefile
168
166
  - lib/fit_parser.rb
@@ -223,7 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
223
221
  version: '0'
224
222
  requirements: []
225
223
  rubyforge_project:
226
- rubygems_version: 2.0.6
224
+ rubygems_version: 2.4.8
227
225
  signing_key:
228
226
  specification_version: 4
229
227
  summary: ''
@@ -1,20 +0,0 @@
1
- Copyright (c) 2011 Jeff Wallace
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.