當前位置: 首頁>>代碼示例>>Golang>>正文


Golang models.SortCodeData類代碼示例

本文整理匯總了Golang中github.com/AntoineAugusti/moduluschecking/models.SortCodeData的典型用法代碼示例。如果您正苦於以下問題:Golang SortCodeData類的具體用法?Golang SortCodeData怎麽用?Golang SortCodeData使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了SortCodeData類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: 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
}
開發者ID:AntoineAugusti,項目名稱:moduluschecking,代碼行數:27,代碼來源:exception2And9.go

示例2: 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)
}
開發者ID:AntoineAugusti,項目名稱:moduluschecking,代碼行數:8,代碼來源:exception3.go

示例3: 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
}
開發者ID:AntoineAugusti,項目名稱:moduluschecking,代碼行數:13,代碼來源:exception10.go

示例4: checkForSortCodeData

// Perform the check for a bank account and a given attempt.
func (r Resolver) checkForSortCodeData(b m.BankAccount, scData m.SortCodeData, attempt int) bool {
	// If the sort code follows an exception
	if scData.HasException() {
		// Try to find a checker for this specific exception
		if checkerFound, hasKey := r.exceptionCheckers[scData.ExceptionValue]; hasKey {
			// Check that this checker can actually handle this case
			if checkerFound.Handles(b, scData, attempt) {
				// Validate the bank account number
				return checkerFound.IsValid(b, scData, attempt)
			}
		}
	}

	// General case
	return checkers.GeneralChecker{}.IsValid(b, scData, attempt)
}
開發者ID:AntoineAugusti,項目名稱:moduluschecking,代碼行數:17,代碼來源:resolver.go

示例5: IsValid

// Tell if the bank account is valid
func (e Exception2Checker) IsValid(b m.BankAccount, sc m.SortCodeData, attempt int) bool {
	if !e.Handles(b, sc, attempt) {
		panic("Should be exception of type 2")
	}

	sc.Weights = WeightsForException2Or9(b, sc)

	return GeneralChecker{}.IsValid(b, sc, attempt)
}
開發者ID:AntoineAugusti,項目名稱:moduluschecking,代碼行數:10,代碼來源:exception2.go

示例6: IsValid

// Tell if the bank account is valid
func (e Exception10Checker) IsValid(b m.BankAccount, sc m.SortCodeData, attempt int) bool {
	if !e.Handles(b, sc, attempt) {
		panic("Should be exception of type 10")
	}

	// Put 8 zeros at the beginning of the weights
	// and keep the original weights after
	zeros := []int{0, 0, 0, 0, 0, 0, 0, 0}
	sc.Weights = append(zeros, sc.Weights[8:]...)

	return GeneralChecker{}.IsValid(b, sc, attempt)
}
開發者ID:AntoineAugusti,項目名稱:moduluschecking,代碼行數:13,代碼來源:exception10.go

示例7: 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)
}
開發者ID:AntoineAugusti,項目名稱:moduluschecking,代碼行數:16,代碼來源:exception9.go

示例8: Handles

// Determine if the checker is able to validate the bank account
func (e Exception6Checker) Handles(b m.BankAccount, sc m.SortCodeData, attempt int) bool {
	return sc.IsException(6)
}
開發者ID:AntoineAugusti,項目名稱:moduluschecking,代碼行數:4,代碼來源:exception6.go

示例9: 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
}
開發者ID:AntoineAugusti,項目名稱:moduluschecking,代碼行數:7,代碼來源:exception7.go


注:本文中的github.com/AntoineAugusti/moduluschecking/models.SortCodeData類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。