Add new helper string related to justified MCQ flag
This commit is contained in:
parent
11e0b46034
commit
c5b65289d3
10 changed files with 121 additions and 69 deletions
31
libfic/mcq_justification.go
Normal file
31
libfic/mcq_justification.go
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package fic
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type FlagLabel struct {
|
||||
Label string
|
||||
IdChoice int64
|
||||
Checksum []byte
|
||||
Solved bool
|
||||
}
|
||||
|
||||
// IsMCQJustification tells you if this key represent a justification from a MCQ.
|
||||
func (k Flag) IsMCQJustification() (bool) {
|
||||
return len(k.Label) > 0 && k.Label[0] == '%'
|
||||
}
|
||||
|
||||
// GetMCQJustification returns the structure corresponding to the given flag.
|
||||
func (k Flag) GetMCQJustification() (fl FlagLabel, err error) {
|
||||
spl := strings.Split(k.Label, "%")
|
||||
if len(spl) >= 3 && len(spl[0]) == 0 {
|
||||
fl.IdChoice, err = strconv.ParseInt(spl[1], 10, 64)
|
||||
fl.Label = strings.Join(spl[2:], "%")
|
||||
} else {
|
||||
err = errors.New("This is not a MCQ justification")
|
||||
}
|
||||
return
|
||||
}
|
||||
Reference in a new issue