2018-12-02 03:52:15 +00:00
|
|
|
package fic
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"strconv"
|
2021-08-30 16:33:14 +00:00
|
|
|
"strings"
|
2018-12-02 03:52:15 +00:00
|
|
|
)
|
|
|
|
|
2022-01-21 12:06:37 +00:00
|
|
|
type FlagMCQLabel struct {
|
2018-12-02 03:52:15 +00:00
|
|
|
Label string
|
2021-08-30 16:33:14 +00:00
|
|
|
IdChoice int
|
2018-12-02 03:52:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// IsMCQJustification tells you if this key represent a justification from a MCQ.
|
2021-08-30 16:33:14 +00:00
|
|
|
func (k FlagKey) IsMCQJustification() bool {
|
2018-12-02 03:52:15 +00:00
|
|
|
return len(k.Label) > 0 && k.Label[0] == '%'
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetMCQJustification returns the structure corresponding to the given flag.
|
2022-01-21 12:06:37 +00:00
|
|
|
func (k FlagKey) GetMCQJustification() (fl FlagMCQLabel, err error) {
|
2018-12-02 03:52:15 +00:00
|
|
|
spl := strings.Split(k.Label, "%")
|
|
|
|
if len(spl) >= 3 && len(spl[0]) == 0 {
|
2021-08-30 16:33:14 +00:00
|
|
|
var idChoice int64
|
|
|
|
idChoice, err = strconv.ParseInt(spl[1], 10, 32)
|
|
|
|
fl.IdChoice = int(idChoice)
|
2018-12-02 03:52:15 +00:00
|
|
|
fl.Label = strings.Join(spl[2:], "%")
|
|
|
|
} else {
|
2021-11-22 14:35:07 +00:00
|
|
|
err = errors.New("this is not a MCQ justification")
|
2018-12-02 03:52:15 +00:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|