📝 README and inline docs

This commit is contained in:
Brian Wiborg 2024-05-14 10:26:48 +02:00
parent d533a879ef
commit c61300c6b8
No known key found for this signature in database
GPG key ID: BE53FA9286B719D6
14 changed files with 139 additions and 24 deletions

View file

@ -5,8 +5,10 @@ import (
"strings"
)
// Quorum defines a custom uint8 type for storing a quorum.
type Quorum uint8
// Supported quorums are:
const (
Simple Quorum = iota
OneFifth
@ -21,6 +23,7 @@ const (
Unanimous
)
// ValidQuorums returns a []Quorum of all supported quorums.
func ValidQuorums() []Quorum {
return []Quorum{
Simple, Unanimous,
@ -31,6 +34,8 @@ func ValidQuorums() []Quorum {
}
}
// FromString takes a string and returns an initialized Quorum or an error if
// the string could not be parsed.
func FromString(s string) (Quorum, error) {
for _, q := range ValidQuorums() {
if strings.ToUpper(q.String()) == strings.ToUpper(s) {
@ -40,6 +45,7 @@ func FromString(s string) (Quorum, error) {
return Simple, fmt.Errorf("inalid quorum: %s", s)
}
// String implements fmt.Stringer
func (q Quorum) String() string {
switch q {
case Simple:
@ -69,6 +75,8 @@ func (q Quorum) String() string {
}
}
// IsSatisfied takes the number of eligible and actual votes and returns a bool
// indicating if the quroum is satisfied or not.
func (q Quorum) IsSatisfied(possibleVotes, totalVotes int) bool {
if totalVotes == 0 {
return false