Debian Codegraph @

common/logical_value.go

raw
1 package common
2
3 import (
4 "errors"
5 "strings"
6 )
7
8 var (
9 // ErrIllegalArgument is returned when illegal argument
10 ErrIllegalArgument = errors.New("Illegal argument")
11 )
12
13 // LogicalValue represents a Logical Value.
14 // @see <a href="http://cpe.mitre.org">cpe.mitre.org</a> for more information.
15 // @author JKRAUNELIS
16 // @email [email protected]
17 type LogicalValue struct {
18 Any bool
19 Na bool
20 }
21
22 // NewLogicalValue returns Logicalvalue
23 func NewLogicalValue(t string) (lv LogicalValue, err error) {
24 t = strings.ToUpper(t)
25 if t == "ANY" {
26 lv.Any = true
27 } else if t == "NA" {
28 lv.Na = true
29 } else {
30 return LogicalValue{}, ErrIllegalArgument
31 }
32 return lv, nil
33 }
34
35 // IsANY returns whether any is true
36 func (lv LogicalValue) IsANY() bool {
37 return lv.Any
38 }
39
40 // IsNA returns whether na is true
41 func (lv LogicalValue) IsNA() bool {
42 return lv.Na
43 }
44
45 // String : String
46 func (lv LogicalValue) String() string {
47 if lv.Any {
48 return "ANY"
49 }
50 return "NA"
51 }