-
Notifications
You must be signed in to change notification settings - Fork 7
/
cns.go
38 lines (32 loc) · 775 Bytes
/
cns.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
package brdocs
import (
"github.com/brazanation/go-documents/internal"
"github.com/brazanation/go-documents/internal/calculator"
)
const CnsType internal.DocumentType = "Cns"
const (
cnsLength int = 15
cnsNumberOfDigits int = 1
cnsValidatorRegex string = `^([\d]{3})([\d]{4})([\d]{4})([\d]{4})$`
cnsFormatterRegex string = "$1 $2 $3 $4"
)
type cns struct {
}
// NewCns is the constructor of cns
func NewCns(number string) (internal.Document, error) {
d, err := internal.NewDocument(
CnsType,
number,
cnsLength,
cnsNumberOfDigits,
cnsFormatterRegex,
cnsValidatorRegex,
cns{},
)
return d, err
}
func (d cns) CalculateDigit(base string) string {
c := calculator.NewCnsCalculator(base)
digit := c.CalculateDigit(base)
return digit
}