src

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

diet.go (718B)


      1 package diet
      2 
      3 import "code.dwrz.net/src/pkg/dqs/category"
      4 
      5 type Diet string
      6 
      7 const (
      8 	Omnivore   Diet = "omnivore"
      9 	Vegan      Diet = "vegan"
     10 	Vegetarian Diet = "vegetarian"
     11 )
     12 
     13 func Valid(d Diet) bool {
     14 	switch d {
     15 	case Omnivore, Vegan, Vegetarian:
     16 		return true
     17 	default:
     18 		return false
     19 	}
     20 }
     21 
     22 func (d Diet) Template() map[string]category.Category {
     23 	switch d {
     24 	case Omnivore:
     25 		return omnivore
     26 	case Vegan:
     27 		return vegan
     28 	case Vegetarian:
     29 		return vegetarian
     30 	default:
     31 		return nil
     32 	}
     33 }
     34 
     35 func (d Diet) MaxScore() int {
     36 	tmpl := d.Template()
     37 
     38 	var max int
     39 	for _, category := range tmpl {
     40 		for _, portion := range category.Portions {
     41 			if portion.Points > 0 {
     42 				max += portion.Points
     43 			}
     44 		}
     45 	}
     46 
     47 	return max
     48 }