diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2023-01-15 22:40:41 -0330 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2023-01-15 22:40:41 -0330 |
| commit | b6247a8372eb18a19c35a924316941d6c1e585d2 (patch) | |
| tree | eb7c1db8ff7f4524f3ac093d6f445ee52c747302 /volume/volume.go | |
| parent | 585fbf852c1e76470df42ebe99ede62440ce19d9 (diff) | |
| download | volute-b6247a8372eb18a19c35a924316941d6c1e585d2.zip | |
volume
Diffstat (limited to 'volume/volume.go')
| -rw-r--r-- | volume/volume.go | 44 |
1 files changed, 0 insertions, 44 deletions
diff --git a/volume/volume.go b/volume/volume.go deleted file mode 100644 index 48330df..0000000 --- a/volume/volume.go +++ /dev/null @@ -1,44 +0,0 @@ -package volume - -import ( - "errors" - "fmt" -) - -type Volume float32 - -const ( - CubicCentimetre Volume = 1 - Litre Volume = 1_000 - CubicMetre Volume = 1_000_000 - 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)) - } -} |