Skip to content

Commit

Permalink
Create measurements from string representation (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Apr 20, 2020
1 parent 92f3bc3 commit 612973d
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions meters/measurements.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package meters

import (
"fmt"
"strings"
"time"
)

Expand Down Expand Up @@ -263,3 +264,15 @@ func (m *Measurement) Description() string {
}
return description
}

// UnStringMeasurement converts case insensitive string to a measurement value
func UnStringMeasurement(s string) Measurement {
s = strings.ToLower(s)
l := strings.ToLower(_Measurement_name)
for i := 0; i < len(_Measurement_index)-1; i++ {
if s == l[_Measurement_index[i]:_Measurement_index[i+1]] {
return Measurement(i + 1)
}
}
return Measurement(0)
}

0 comments on commit 612973d

Please sign in to comment.