From 31605150d3e10b08dad2086005c64664f5648a51 Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Fri, 27 May 2022 22:39:03 -0230 Subject: prepare to switch ui library --- volume/volume.go | 34 ++-------------------------------- 1 file changed, 2 insertions(+), 32 deletions(-) (limited to 'volume') diff --git a/volume/volume.go b/volume/volume.go index 48330df..e634b5d 100644 --- a/volume/volume.go +++ b/volume/volume.go @@ -1,10 +1,5 @@ package volume -import ( - "errors" - "fmt" -) - type Volume float32 const ( @@ -14,31 +9,6 @@ const ( CubicInch Volume = 16.38706 ) -// UnitStrings returns a slice of strings, each representing a -// unit. -// This is necessary because giu.Combo only works with strings. -func UnitStrings() []string { - return []string{"cc", "L", "m³", "in³"} -} - -const ( - DefaultUnit Volume = CubicCentimetre - // DefaulUnitIndex is used to index UnitStrings(). - DefaultUnitIndex int32 = 0 // cc -) - -func UnitFromString(s string) (Volume, error) { - // Each case corresponds to a value in UnitStrings(). - switch s { - case "cc": - return CubicCentimetre, nil - case "L": - return Litre, nil - case "m³": - return CubicMetre, nil - case "in³": - return CubicInch, nil - default: - return *new(Volume), errors.New(fmt.Sprintf("invalid volume unit: '%s'", s)) - } +func (v Volume) As(unit Volume) float32 { + return float32(v / unit) } -- cgit v1.2.3