idiomatic project structure
This commit is contained in:
55
internal/models/keypad_dimension.go
Normal file
55
internal/models/keypad_dimension.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"go-nkode/config"
|
||||
py "go-nkode/internal/utils"
|
||||
)
|
||||
|
||||
type KeypadDimension struct {
|
||||
AttrsPerKey int `json:"attrs_per_key"`
|
||||
NumbOfKeys int `json:"numb_of_keys"`
|
||||
}
|
||||
|
||||
func (kp *KeypadDimension) TotalAttrs() int {
|
||||
return kp.AttrsPerKey * kp.NumbOfKeys
|
||||
}
|
||||
|
||||
func (kp *KeypadDimension) IsDispersable() bool {
|
||||
return kp.AttrsPerKey <= kp.NumbOfKeys
|
||||
}
|
||||
|
||||
func (kp *KeypadDimension) IsValidKeypadDimension() error {
|
||||
if KeypadMin.AttrsPerKey > kp.AttrsPerKey || KeypadMax.AttrsPerKey < kp.AttrsPerKey || KeypadMin.NumbOfKeys > kp.NumbOfKeys || KeypadMax.NumbOfKeys < kp.NumbOfKeys {
|
||||
return config.ErrInvalidKeypadDimensions
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (kp *KeypadDimension) ValidKeySelections(selectedKeys []int) bool {
|
||||
return py.All[int](selectedKeys, func(idx int) bool {
|
||||
return 0 <= idx && idx < kp.NumbOfKeys
|
||||
})
|
||||
}
|
||||
|
||||
func (kp *KeypadDimension) ValidateAttributeIndices(attrIndicies []int) bool {
|
||||
return py.All[int](attrIndicies, func(i int) bool {
|
||||
return i >= 0 && i < kp.TotalAttrs()
|
||||
})
|
||||
}
|
||||
|
||||
var (
|
||||
KeypadMax = KeypadDimension{
|
||||
AttrsPerKey: 16,
|
||||
NumbOfKeys: 15,
|
||||
}
|
||||
|
||||
KeypadMin = KeypadDimension{
|
||||
AttrsPerKey: 5,
|
||||
NumbOfKeys: 4,
|
||||
}
|
||||
|
||||
KeypadDefault = KeypadDimension{
|
||||
AttrsPerKey: 14,
|
||||
NumbOfKeys: 7,
|
||||
}
|
||||
)
|
||||
Reference in New Issue
Block a user