clipr 0.2.0
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 +7 -0
- data/.gitignore +5 -0
- data/Gemfile +7 -0
- data/README.md +22 -0
- data/Rakefile +1 -0
- data/bin/clipr +31 -0
- data/clipr.gemspec +19 -0
- data/lib/clipr.rb +2 -0
- data/lib/clipr/tcx_file.rb +121 -0
- data/lib/clipr/version.rb +3 -0
- data/lib/trollop.rb +782 -0
- data/spec/fixtures/sample_activity.tcx +47184 -0
- data/spec/fixtures/tony.tcx +16948 -0
- data/spec/lib/tcx_file_spec.rb +91 -0
- data/spec/spec_helper.rb +9 -0
- metadata +63 -0
| @@ -0,0 +1,91 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Clipr::TCXFile do
         | 
| 4 | 
            +
              before(:all) do
         | 
| 5 | 
            +
                @file = Clipr::TCXFile.new(content_file('sample_activity.tcx'))
         | 
| 6 | 
            +
              end
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              subject(:file) { @file }
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              it { should have(1).laps }
         | 
| 11 | 
            +
              it { should have(3370).trackpoints }
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              its(:reported_avg_speed) { should eql(4.431000232696533) }
         | 
| 14 | 
            +
              its(:real_avg_speed) { should eql(5.665456157569008) }
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              its(:reported_total_distance) { should eql(42981.54) }
         | 
| 17 | 
            +
              its(:real_total_distance) { should eql(42981.53125) }
         | 
| 18 | 
            +
              its(:reported_total_seconds) { should eql(9700.176) }
         | 
| 19 | 
            +
              its(:real_total_seconds) { should eql(9704.0) }
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              describe "A clipped file" do
         | 
| 22 | 
            +
                before(:all) { @file.clip_after(time: '2013-04-13T11:32:11.000Z') }
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                it 'deletes all following trackpoints' do
         | 
| 25 | 
            +
                  file.should have(3147).trackpoints
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                it 'calculates the average speed' do
         | 
| 29 | 
            +
                  file.real_avg_speed.should == 6.051869161249457
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                it 'sets the reported speed' do
         | 
| 33 | 
            +
                  file.reported_avg_speed.should == 6.051869161249457
         | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                it 'calculates the total distance' do
         | 
| 37 | 
            +
                  file.real_total_distance.should == 42847.98046875
         | 
| 38 | 
            +
                end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                it 'sets the reported total distance' do
         | 
| 41 | 
            +
                  file.reported_total_distance.should == 42847.98046875
         | 
| 42 | 
            +
                end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                it 'calculates the maximum speed' do
         | 
| 45 | 
            +
                  file.real_max_speed.should == 14.213000297546387
         | 
| 46 | 
            +
                end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                it 'sets the maximum speed' do
         | 
| 49 | 
            +
                  file.reported_max_speed.should == 14.213000297546387
         | 
| 50 | 
            +
                end
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                it 'calculates the total time' do
         | 
| 53 | 
            +
                  file.real_total_seconds.should == 8091.0
         | 
| 54 | 
            +
                end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                it 'sets the total time' do
         | 
| 57 | 
            +
                  file.reported_total_seconds.should == 8091.0
         | 
| 58 | 
            +
                end
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                describe 'The saved file' do
         | 
| 61 | 
            +
                  before :all do
         | 
| 62 | 
            +
                    saved_name = content_filename('saved.tcx')
         | 
| 63 | 
            +
                    File.delete(saved_name) rescue nil
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                    @file.save(saved_name).should be_true
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                    @loaded_str = content_file('saved.tcx')
         | 
| 68 | 
            +
                  end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                  context 'as xml' do
         | 
| 71 | 
            +
                    subject(:loaded_xml) { Nokogiri::XML(@loaded_str) }
         | 
| 72 | 
            +
             | 
| 73 | 
            +
                    it 'has one activity in the Garmin namespace' do
         | 
| 74 | 
            +
                      loaded_xml.xpath('//xmlns:Activity').should have(1).node
         | 
| 75 | 
            +
                    end
         | 
| 76 | 
            +
             | 
| 77 | 
            +
                    it 'has the correct speed' do
         | 
| 78 | 
            +
                      loaded_xml.xpath('//xmlns:Lap/xmlns:TotalTimeSeconds').text.to_f.should == 8091.0
         | 
| 79 | 
            +
                    end
         | 
| 80 | 
            +
                  end
         | 
| 81 | 
            +
                end
         | 
| 82 | 
            +
              end
         | 
| 83 | 
            +
             | 
| 84 | 
            +
              describe 'A file with trackpoints that have no distance' do
         | 
| 85 | 
            +
                before(:all) do
         | 
| 86 | 
            +
                  @file = Clipr::TCXFile.new(content_file('tony.tcx'))
         | 
| 87 | 
            +
                end
         | 
| 88 | 
            +
             | 
| 89 | 
            +
                its(:real_total_distance) { should eql(53917.5) }
         | 
| 90 | 
            +
              end
         | 
| 91 | 
            +
            end
         | 
    
        data/spec/spec_helper.rb
    ADDED
    
    
    
        metadata
    ADDED
    
    | @@ -0,0 +1,63 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: clipr
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.2.0
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Russell Garner
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2013-08-26 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies: []
         | 
| 13 | 
            +
            description: Trims single-lap Garmin TCX files to remove empty space at the end of
         | 
| 14 | 
            +
              the file
         | 
| 15 | 
            +
            email:
         | 
| 16 | 
            +
            - rgarner@zephyros-systems.co.uk
         | 
| 17 | 
            +
            executables:
         | 
| 18 | 
            +
            - clipr
         | 
| 19 | 
            +
            extensions: []
         | 
| 20 | 
            +
            extra_rdoc_files: []
         | 
| 21 | 
            +
            files:
         | 
| 22 | 
            +
            - .gitignore
         | 
| 23 | 
            +
            - Gemfile
         | 
| 24 | 
            +
            - README.md
         | 
| 25 | 
            +
            - Rakefile
         | 
| 26 | 
            +
            - bin/clipr
         | 
| 27 | 
            +
            - clipr.gemspec
         | 
| 28 | 
            +
            - lib/clipr.rb
         | 
| 29 | 
            +
            - lib/clipr/tcx_file.rb
         | 
| 30 | 
            +
            - lib/clipr/version.rb
         | 
| 31 | 
            +
            - lib/trollop.rb
         | 
| 32 | 
            +
            - spec/fixtures/sample_activity.tcx
         | 
| 33 | 
            +
            - spec/fixtures/tony.tcx
         | 
| 34 | 
            +
            - spec/lib/tcx_file_spec.rb
         | 
| 35 | 
            +
            - spec/spec_helper.rb
         | 
| 36 | 
            +
            homepage: http://github.com/rgarner/clipr
         | 
| 37 | 
            +
            licenses: []
         | 
| 38 | 
            +
            metadata: {}
         | 
| 39 | 
            +
            post_install_message: 
         | 
| 40 | 
            +
            rdoc_options: []
         | 
| 41 | 
            +
            require_paths:
         | 
| 42 | 
            +
            - lib
         | 
| 43 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 44 | 
            +
              requirements:
         | 
| 45 | 
            +
              - - '>='
         | 
| 46 | 
            +
                - !ruby/object:Gem::Version
         | 
| 47 | 
            +
                  version: '0'
         | 
| 48 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 49 | 
            +
              requirements:
         | 
| 50 | 
            +
              - - '>='
         | 
| 51 | 
            +
                - !ruby/object:Gem::Version
         | 
| 52 | 
            +
                  version: '0'
         | 
| 53 | 
            +
            requirements: []
         | 
| 54 | 
            +
            rubyforge_project: 
         | 
| 55 | 
            +
            rubygems_version: 2.0.3
         | 
| 56 | 
            +
            signing_key: 
         | 
| 57 | 
            +
            specification_version: 4
         | 
| 58 | 
            +
            summary: Trim Garmin TCX files
         | 
| 59 | 
            +
            test_files:
         | 
| 60 | 
            +
            - spec/fixtures/sample_activity.tcx
         | 
| 61 | 
            +
            - spec/fixtures/tony.tcx
         | 
| 62 | 
            +
            - spec/lib/tcx_file_spec.rb
         | 
| 63 | 
            +
            - spec/spec_helper.rb
         |