-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rule.go
56 lines (45 loc) · 1.21 KB
/
rule.go
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
50
51
52
53
54
55
56
// Copyright (c) 2017 Andrey Gayvoronsky <plandem@gmail.com>
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package rule
import (
"github.com/roboninc/xlsx/format/styles"
"github.com/roboninc/xlsx/internal/ml"
)
type validator interface {
Validate(r *Info) error
}
// Info is objects that holds combined information about conditional rule
type Info struct {
initialized bool
rule *ml.ConditionalRule
style *styles.Info
validator validator
}
// Option is helper type to set options for rule
type Option func(o *Info)
// New creates and returns Info object with requested options
func New(options ...Option) *Info {
r := &Info{
rule: &ml.ConditionalRule{},
}
r.Set(options...)
return r
}
// Set sets new options for conditional rule
func (r *Info) Set(options ...Option) {
for _, o := range options {
o(r)
}
}
// Validate validate rule if required
func (r *Info) Validate() error {
if r.validator != nil {
return r.validator.Validate(r)
}
return nil
}
// private method used to access private fields that we want to protect from direct mutating
// func fromRule(r *Info) (*ml.ConditionalRule, *styles.Info) {
// return r.rule, r.style
// }