-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bottom.go
67 lines (57 loc) · 1.39 KB
/
bottom.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
57
58
59
60
61
62
63
64
65
66
67
// 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 (
"fmt"
"github.com/roboninc/xlsx/format/styles"
"github.com/roboninc/xlsx/internal/ml"
"github.com/roboninc/xlsx/internal/ml/primitives"
)
type bottomRule struct {
baseRule
}
// Bottom is helper object to set specific options for rule
var Bottom bottomRule
func (x bottomRule) initIfRequired(r *Info) {
if !r.initialized {
r.initialized = true
r.validator = Bottom
r.rule = &ml.ConditionalRule{
Type: primitives.ConditionTypeTop10,
Rank: 10,
Bottom: true,
}
}
}
func (x bottomRule) Default(r *Info) {
x.initIfRequired(r)
}
func (x bottomRule) Value(rank uint, settings ...interface{}) Option {
return func(r *Info) {
x.initIfRequired(r)
r.rule.Rank = rank
for _, p := range settings {
switch pv := p.(type) {
case string:
if pv == "%" {
r.rule.Percent = true
}
case *styles.Info:
r.style = pv
}
}
}
}
func (x bottomRule) Validate(r *Info) error {
if r.rule.Percent {
if r.rule.Rank < 1 || r.rule.Rank > 100 {
return fmt.Errorf("bottom: value(%d) should be between (1 - 100)", r.rule.Rank)
}
} else {
if r.rule.Rank < 1 || r.rule.Rank > 1000 {
return fmt.Errorf("bottom: value(%d) should be between 1 and 1000", r.rule.Rank)
}
}
return nil
}