src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

units.go (581B)


      1 package units
      2 
      3 type System string
      4 
      5 const (
      6 	Default  System = "metric"
      7 	Imperial System = "imperial"
      8 	Metric   System = "metric"
      9 )
     10 
     11 func Valid(s System) bool {
     12 	switch s {
     13 	case Imperial, Metric:
     14 		return true
     15 	default:
     16 		return false
     17 	}
     18 }
     19 
     20 type Unit string
     21 
     22 const (
     23 	Centimeter Unit = "cm"
     24 	Kilogram   Unit = "kg"
     25 
     26 	Inches Unit = "in"
     27 	Pounds Unit = "lbs"
     28 )
     29 
     30 func (s System) Weight() Unit {
     31 	switch s {
     32 	case Imperial:
     33 		return Pounds
     34 	default:
     35 		return Kilogram
     36 	}
     37 }
     38 
     39 func (s System) Height() Unit {
     40 	switch s {
     41 	case Imperial:
     42 		return Inches
     43 	default:
     44 		return Centimeter
     45 	}
     46 }