-
Notifications
You must be signed in to change notification settings - Fork 7
/
pispasep.go
42 lines (36 loc) · 979 Bytes
/
pispasep.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
package brdocs
import (
"fmt"
"github.com/brazanation/go-documents/internal"
"github.com/brazanation/go-documents/internal/calculator"
)
const PisPasepType internal.DocumentType = "PisPasep"
const (
pisPasepLength int = 11
pisPasepNumberOfDigits int = 1
pisPasepValidatorRegex string = `^([\d]{3})([\d]{5})([\d]{2})([\d]{1})$`
pisPasepFormatterRegex string = "$1.$2.$3-$4"
)
type pisPasep struct {
}
// NewPisPasep is the constructor of pisPasep
func NewPisPasep(number string) (internal.Document, error) {
d, err := internal.NewDocument(
PisPasepType,
number,
pisPasepLength,
pisPasepNumberOfDigits,
pisPasepFormatterRegex,
pisPasepValidatorRegex,
pisPasep{},
)
return d, err
}
func (pisPasep pisPasep) CalculateDigit(base string) string {
c := calculator.NewModule11(base)
c.WithMultipliersInterval(2, 9);
c.UseComplementaryInsteadOfModule();
c.ReplaceWhen(0, 10, 11);
digit := c.Calculate();
return fmt.Sprintf("%d", digit)
}