Skip to content

Commit

Permalink
Merge pull request #12 from asnodgrass/feature/name-and-desc-fields
Browse files Browse the repository at this point in the history
GPX name and description fields
  • Loading branch information
asnodgrass authored May 15, 2017
2 parents 95967dc + 246300e commit 5389c10
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
21 changes: 17 additions & 4 deletions cmd/gpx.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"os"
"fmt"
"log"
"path"
"strings"
"time"
"io"
"io/ioutil"
Expand Down Expand Up @@ -69,7 +71,8 @@ var gpxCmd = &cobra.Command{
trkpts = append(trkpts, recordToTrackPoint(rec))
}

gpxData := generateGPX(trkpts)
name := filenamePrefix(inFile)
gpxData := generateGPX(trkpts, name)
if outFile != "" {
ioutil.WriteFile(outFile, gpxData, 0644)
} else {
Expand Down Expand Up @@ -154,14 +157,14 @@ func recordToTrackPoint(rec v1000.Record) (trackPoint) {
return tp
}

func generateGPX(trkpts []trackPoint) []byte {
func generateGPX(trkpts []trackPoint, name string) []byte {
trksegs := make([]trackSegment, 1)
trksegs[0].TrackPoints = trkpts

trk := track{
TrackSegments: trksegs,
Name: "please fix me",
Description: "and this too",
Name: name,
Description: "V1000 gps tracklog data",
}

bounds := gpxBounds{
Expand Down Expand Up @@ -244,3 +247,13 @@ func maximumLongitude(trkpts []trackPoint) latLong {
}
return high
}

func filenamePrefix(filename string) string {
f := path.Base(filename)
pos := strings.LastIndex(f, ".")
if pos == -1 {
return f
} else {
return f[:pos]
}
}
9 changes: 9 additions & 0 deletions cmd/gpx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,12 @@ func Test_maximumLongitude(t *testing.T) {
t.Errorf("Expected %f, but got %f", expected, out)
}
}

func Test_filenamePrefix(t *testing.T) {
expected := "foo.bar.baz"
t.Logf("Checking for valid filename prefix.. (expected: %s)", expected)
data := "/path/to/foo.bar.baz.gps"
if out := filenamePrefix(data); out != expected {
t.Errorf("Expected %s, but got %s", expected, out)
}
}

0 comments on commit 5389c10

Please sign in to comment.