summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/mcuadros/go-version/constraint.go
blob: 8dc2cfcc642a0a7ab4515cf0030e20286ccb83b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package version

import (
	"strings"
)

type Constraint struct {
	operator string
	version  string
}

// Return a new Constrain and sets operator and version to compare
func NewConstrain(operator, version string) *Constraint {
	constraint := new(Constraint)
	constraint.SetOperator(operator)
	constraint.SetVersion(version)

	return constraint
}

// Sets operator to compare
func (self *Constraint) SetOperator(operator string) {
	self.operator = operator
}

// Get operator to compare
func (self *Constraint) GetOperator() string {
	return self.operator
}

// Sets version to compare
func (self *Constraint) SetVersion(version string) {
	self.version = version
}

// Get version to compare
func (self *Constraint) GetVersion() string {
	return self.version
}

// Match a given version againts the constraint
func (self *Constraint) Match(version string) bool {
	return Compare(version, self.version, self.operator)
}

// Return a string representation
func (self *Constraint) String() string {
	return strings.Trim(self.operator+" "+self.version, " ")
}