Skip to content

Commit

Permalink
Merge pull request #390 from jovandeginste/noname
Browse files Browse the repository at this point in the history
refactor(converters): Improve name detection
  • Loading branch information
jovandeginste authored Jan 9, 2025
2 parents d6b62f2 + 72cdc70 commit 299b7bd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
17 changes: 17 additions & 0 deletions pkg/converters/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@ func Parse(filename string, content []byte) (*gpx.GPX, error) {
return ParseGPX(content)
}

basename := path.Base(filename)

c, err := parseContent(basename, content)
if err != nil {
return nil, err
}

if c.Name != "" || len(c.Tracks) > 0 {
return c, nil
}

c.Name = basename

return c, nil
}

func parseContent(filename string, content []byte) (*gpx.GPX, error) {
suffix := path.Ext(filename)

switch suffix {
Expand Down
2 changes: 1 addition & 1 deletion pkg/database/gpx_sample_1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const GpxSample1 = `<?xml version="1.0" encoding="UTF-8"?>
<time>2012-10-24T23:22:51.000Z</time>
</metadata>
<trk>
<name>Untitled</name>
<name>Some name</name>
<trkseg>
<trkpt lon="-77.02016168273985" lat="38.92747367732227">
<ele>25.600000381469727</ele>
Expand Down
2 changes: 1 addition & 1 deletion pkg/database/workouts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestWorkout_Parse(t *testing.T) {
assert.InDelta(t, 3125, w.Data.TotalDistance, 1)
assert.InDelta(t, 3.297, w.Data.AverageSpeed, 0.01)
assert.InDelta(t, 3.297, w.Data.AverageSpeedNoPause, 0.01)
assert.Equal(t, "Untitled", w.Name)
assert.Equal(t, "Some name", w.Name)
assert.Nil(t, w.Data.Address)
}

Expand Down

0 comments on commit 299b7bd

Please sign in to comment.