Skip to content

Commit 3ea1ae6

Browse files
committed
Added documentation for parsing .TCX.
1 parent 8f468e0 commit 3ea1ae6

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ group :development, :test do
1717
gem 'rubocop', '1.68.0'
1818
gem 'rubocop-rake'
1919
gem 'rubocop-rspec'
20+
gem 'tcx'
2021
gem 'vcr'
2122
gem 'webmock'
2223
gem 'webrick', '~> 1.7'

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,13 +508,18 @@ gpx.tracks # => Array[GPX::Track]
508508

509509
#### Export Route TCX
510510

511-
Returns a [Training Center XML](https://en.wikipedia.org/wiki/Training_Center_XML) (TCX) data of the route. Combine with [multi_xml](https://github.com/sferik/multi_xml) to parse it.
511+
Returns a [Training Center XML](https://en.wikipedia.org/wiki/Training_Center_XML) (TCX) data of the route. Combine with [multi_xml](https://github.com/sferik/multi_xml) or [tcx](https://github.com/dblock/tcx) to parse it.
512512

513513
```ruby
514514
data = client.export_route_tcx(16341573) # => String
515515

516516
require 'multi_xml'
517517
xml = MultiXml.parse(data) # => parsed TCX
518+
519+
require 'tcx'
520+
tcx = Tcx.load(data) # => Tcx::Database
521+
522+
tcx.courses.first.name # => 'Lower Manhattan'
518523
```
519524

520525
#### Get Route

spec/spec_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
require 'multi_xml'
1010
require 'gpx'
11+
require 'tcx'
1112
require 'polylines'
1213

1314
Dir[File.join(File.dirname(__FILE__), 'support', '**/*.rb')].each do |file|

spec/strava/api/client/endpoints/routes/export_route_tcx_spec.rb

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,31 @@
44

55
RSpec.describe 'Strava::Api::Client#export_route_tcx', vcr: { cassette_name: 'client/export_route_tcx' } do
66
include_context 'with API client'
7-
it 'exports a route file' do
8-
route = client.export_route_tcx(id: 16_341_573)
9-
expect(route).to start_with "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<TrainingCenterDatabase"
107

11-
xml = MultiXml.parse(route)
12-
expect(xml).to be_a Hash
8+
describe 'an exported route' do
9+
let(:route) { client.export_route_tcx(id: 16_341_573) }
10+
11+
it 'is a TrainingCenterDatabase' do
12+
expect(route).to start_with "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<TrainingCenterDatabase"
13+
end
14+
15+
describe 'as xml' do
16+
let(:xml) { MultiXml.parse(route) }
17+
18+
it 'is valid XML' do
19+
expect(xml).to be_a Hash
20+
end
21+
end
22+
23+
describe 'as parsed tcx' do
24+
let(:tcx) { Tcx.load(route) }
25+
26+
it 'is valid' do
27+
expect(tcx).to be_a(Tcx::Database)
28+
expect(tcx.courses.count).to eq 1
29+
expect(tcx.courses.first.name).to eq 'Lower Manhattan'
30+
end
31+
end
1332
end
1433

1534
it 'exports a route file by id' do

0 commit comments

Comments
 (0)