aboutsummaryrefslogtreecommitdiffstats
path: root/mass.go
blob: 158bc3740e6c658bb6fcac72d55ac2f970db53f3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package main

import (
	"errors"
	"fmt"
)

type MassFlowRate float32

const (
	KilogramsPerSecond MassFlowRate = 1
	PoundsPerMinute    MassFlowRate = 0.007_559_872_833
)

var MassFlowRateUnits = []string{"kg/s", "lb/min"}

func ParseMassFlowRateUnit(s string) (MassFlowRate, error) {
	// Each case corresponds to a value in MassFlowRateUnits.
	switch s {
	case "kg/s":
		return KilogramsPerSecond, nil
	case "lb/min":
		return PoundsPerMinute, nil
	default:
		return *new(MassFlowRate), errors.New(
			fmt.Sprintf("invalid mass flow rate unit: '%s'", s))
	}
}