本文整理匯總了Golang中github.com/AntoineAugusti/moduluschecking/models.BankAccount類的典型用法代碼示例。如果您正苦於以下問題:Golang BankAccount類的具體用法?Golang BankAccount怎麽用?Golang BankAccount使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了BankAccount類的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: FollowsException3
// Check if we follow the criteria of the exception 3
func FollowsException3(b m.BankAccount, scData m.SortCodeData) bool {
c := b.NumberAtPosition("c")
hasNextAnd3 := scData.HasNext() && scData.Next.IsException(3)
return (scData.IsException(3) || hasNextAnd3) && (c == 6 || c == 9)
}
示例2: IsValid
// Tell if the bank account is valid
func (e Exception5Checker) IsValid(b m.BankAccount, sc m.SortCodeData, attempt int) bool {
if !e.Handles(b, sc, attempt) {
panic("Should be exception of type 5")
}
if substitution, hasKey := e.Substitutions[b.SortCode]; hasKey {
b.SortCode = substitution
}
// First attempt
if attempt == 1 {
checkDigit := b.NumberAtPosition("g")
remainder := GeneralChecker{}.RemainderFromRegularCheck(b, sc)
if remainder == 0 && checkDigit == 0 {
return true
}
if remainder == 1 {
return false
}
return (11 - remainder) == checkDigit
}
// Second attempt
checkDigit := b.NumberAtPosition("h")
remainder := GeneralChecker{}.RemainderFromRegularCheck(b, sc)
if remainder == 0 && checkDigit == 0 {
return true
}
return (10 - remainder) == checkDigit
}
示例3: WeightsForException2Or9
// Get weights to use for a bank account following the exception 2 or 9.
func WeightsForException2Or9(b m.BankAccount, sc m.SortCodeData) (weights []int) {
if !(sc.IsException(2) || sc.IsException(9)) {
panic("Expected exception 2 or exception 9 sort code")
}
a := b.NumberAtPosition("a")
g := b.NumberAtPosition("g")
// Default weights
weights = sc.Weights
switch {
case a != 0 && g != 9:
weights = []int{
0, 0, 1, 2, 5, 3,
6, 4, 8, 7, 10, 9, 3, 1,
}
case a != 0 && g == 9:
weights = []int{
0, 0, 0, 0, 0, 0,
0, 0, 8, 7, 10, 9, 3, 1,
}
}
return
}
示例4: isForeignCurrency
// Check if a bank account is in a foreign currency
func (e Exception6Checker) isForeignCurrency(b m.BankAccount) bool {
// if a = 4, 5, 6, 7 or 8, and g and h are the same,
// the accounts are for a foreign currency and the checks cannot be used
a := b.NumberAtPosition("a")
g := b.NumberAtPosition("g")
h := b.NumberAtPosition("h")
return a >= 4 && a <= 8 && (g == h)
}
示例5: IsValid
// Tell if the bank account is valid
func (e Exception4Checker) IsValid(b m.BankAccount, sc m.SortCodeData, attempt int) bool {
if !e.Handles(b, sc, attempt) {
panic("Should be exception of type 4")
}
g := b.NumberAtPosition("g")
h := b.NumberAtPosition("h")
checkDigit := g*10 + h
return GeneralChecker{}.RemainderFromRegularCheck(b, sc) == checkDigit
}
示例6: Handles
// Determine if the checker is able to validate the bank account
func (e Exception10Checker) Handles(account m.BankAccount, sc m.SortCodeData, attempt int) bool {
if !sc.IsException(10) {
return false
}
// if ab = 09 or ab = 99 and g = 9
a := account.NumberAtPosition("a")
b := account.NumberAtPosition("b")
g := account.NumberAtPosition("g")
return (a == 0 || a == 9) && b == 9 && g == 9
}
示例7: DoubleAlternate
// Perform the double alternate algorithm and return
// the remainder of the operation
func DoubleAlternate(b m.BankAccount, data m.SortCodeData, sum int) (remainder int) {
numbers := b.MergeAccountDetails()
weights := data.Weights
for i, nb := range numbers {
sum += helpers.AddDigits(weights[i] * nb)
}
remainder = sum % 10
return
}
示例8: Modulus
// Perform the modulus algorithm with a given modulus
// and return the remainder of the operation
func Modulus(b m.BankAccount, modulus int, data m.SortCodeData) (remainder int) {
numbers := b.MergeAccountDetails()
sum := 0
weights := data.Weights
for i, nb := range numbers {
sum += weights[i] * nb
}
remainder = sum % modulus
return
}
示例9: IsValid
// Tell if the bank account is valid
func (e Exception14Checker) IsValid(b m.BankAccount, sc m.SortCodeData, attempt int) bool {
if !e.Handles(b, sc, attempt) {
panic("Should be exception of type 14 at attempt 2")
}
h := b.NumberAtPosition("h")
if h >= 2 && h <= 8 {
return false
}
// Remove the 1st digit from the accout number and insert a 0
// as the 1st digit for check purposes
b.AccountNumber = "0" + b.AccountNumber[0:len(b.AccountNumber)-1]
return GeneralChecker{}.IsValid(b, sc, attempt)
}
示例10: IsValid
// Tell if the bank account is valid
func (e Exception9Checker) IsValid(b m.BankAccount, sc m.SortCodeData, attempt int) bool {
if !e.Handles(b, sc, attempt) {
panic("Should be exception of type 9")
}
sc.Weights = WeightsForException2Or9(b, sc)
if (GeneralChecker{}.IsValid(b, sc, attempt)) {
return true
}
// Try to replace the sort code
b.SortCode = "309634"
return GeneralChecker{}.IsValid(b, e.Weights[b.SortCode], attempt)
}
示例11: Handles
// Determine if the checker is able to validate the bank account
func (e Exception7Checker) Handles(account m.BankAccount, sc m.SortCodeData, attempt int) bool {
// If g=9
g := account.NumberAtPosition("g")
return sc.IsException(7) && g == 9
}