From 6691b4a053833891ac63240909d3d032c61c357f Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Sat, 7 May 2016 15:27:03 +0200 Subject: [PATCH] Fix: Reduced complexity of hydrant functions --- hydrant.go | 42 ++++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/hydrant.go b/hydrant.go index de52da3..7feccef 100644 --- a/hydrant.go +++ b/hydrant.go @@ -9,6 +9,21 @@ import ( "github.com/Luzifer/gpxhydrant/osm" ) +var ( + hydrantPositions = map[string]string{ + "S": "sidewalk", + "P": "parking_lot", + "L": "lane", + "G": "green", + } + hydrantTypes = map[string]string{ + "U": "underground", + "O": "pillar", + "W": "wall", + "P": "pond", + } +) + type hydrant struct { /* @@ -45,27 +60,8 @@ func parseWaypoint(in gpx.Waypoint) (*hydrant, error) { Pressure: cfg.Pressure, } - switch matches[1] { - case "S": - out.Position = "sidewalk" - case "P": - out.Position = "parking_lot" - case "L": - out.Position = "lane" - case "G": - out.Position = "green" - } - - switch matches[2] { - case "U": - out.Type = "underground" - case "O": - out.Type = "pillar" - case "W": - out.Type = "wall" - case "P": - out.Type = "pond" - } + out.Position = hydrantPositions[matches[1]] + out.Type = hydrantTypes[matches[2]] if matches[3] != "?" { diameter, err := strconv.ParseInt(matches[3], 10, 64) @@ -93,9 +89,7 @@ func fromNode(in *osm.Node) (*hydrant, error) { for _, t := range in.Tags { switch t.Key { case "emergency": - if t.Value == "fire_hydrant" { - validFireHydrant = true - } + validFireHydrant = t.Value == "fire_hydrant" case "fire_hydrant:diameter": if out.Diameter, e = strconv.ParseInt(t.Value, 10, 64); e != nil { return nil, e