bib

package
v0.0.0-...-b2e6541 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 8, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Signs that it is a book reference.
	BookRef refType = iota
	// Signs that it is a chapter reference.
	ChapterRef
	// Signs that the reference contains a single verse.
	SingleVerseRef
	// Signs that the reference contains a verse range.
	RangeVerseRef
	// Signs that the reference contains a list of verses.
	ListVerseRef
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Book

type Book struct {
	// Version is a reference to the version which the book belongs to.
	Version  *Version
	Number   int
	Name     string
	Chapters []Chapter
}

Book docs here.

func (*Book) FirstChapter

func (bk *Book) FirstChapter() *Chapter

FirstChapter docs here.

func (*Book) GetChapter

func (bk *Book) GetChapter(num int) *Chapter

GetChapter docs here.

func (*Book) Next

func (bk *Book) Next() *Book

Next docs here.

func (*Book) Previous

func (bk *Book) Previous() *Book

Previous docs here.

func (*Book) Ref

func (bk *Book) Ref() Ref

Ref docs here.

func (*Book) Verses

func (bk *Book) Verses() []*Verse

Verses docs here.

type Branch

type Branch[K comparable, V any] struct {
	// contains filtered or unexported fields
}

Branch gathers a matching key, an optional value (ending branches should always have a value; root branch should never have a value) and its subbranches.

func NewTree

func NewTree[K comparable, V any]() *Branch[K, V]

NewTree returns a new tree with no branches.

func (*Branch[K, V]) Insert

func (branch *Branch[K, V]) Insert(key []K, val *V)

Insert inserts a key in a branch, creating subbranches necessary to accomodate its path to given a value, which will be attached to the end of the branch.

func (*Branch[K, V]) Search

func (branch *Branch[K, V]) Search(key []K) *V

Search searches for a key in a branch and its subbranches. If a unumbiguous value is found, it is returned; otherwise, yields nil. An unumbiguous value is only asserted with partial keys. A partial key doesn't contain all the values needed to match an entire key, but can match a value if there's only one subbranch in the branch that it reached. TODO: include a drawing illustrating this concept.

type Chapter

type Chapter struct {
	// Book is a reference to the book which the chapter belongs to.
	Book   *Book
	Number int
	Verses []Verse
}

Chapter docs here.

func (*Chapter) GetVerse

func (chap *Chapter) GetVerse(num int) *Verse

GetVerse docs here.

func (*Chapter) LastVerse

func (chap *Chapter) LastVerse() *Verse

LastVerse docs here.

func (*Chapter) Next

func (chap *Chapter) Next() *Chapter

Next docs here.

func (*Chapter) Previous

func (chap *Chapter) Previous() *Chapter

Previous docs here.

func (*Chapter) Ref

func (chap *Chapter) Ref() Ref

Ref docs here.

func (*Chapter) VerseRange

func (chap *Chapter) VerseRange(from, to int) []*Verse

VerseRange docs here.

type Ref

type Ref struct {
	// Type indicates how the reference should be interpreted. See RefType and
	// constants of this type.
	Type refType
	// BookName references the book name. Relevant to all types, for it must
	// always be present.
	BookName string
	// ChapterNum references the chapter number. Relevant for type ChapterRef,
	// SingleVerseRef, RangeVerseRef and ListVerseRef.
	ChapterNum int
	// VerseNum references the lower index when the type is RangeVerseRef, or
	// the verse number when the type is SingleVerseRef.
	VerseNum int
	// EndVerseNum references the higher index when the type is RangeVerseRef.
	EndVerseNum int
	// VerseNums  references unrelated verse numbers when the type is
	// ListVerseRef.
	VerseNums []int
}

Ref represents a generic reference of a verse, or a collection of verses, that can be indepently built and applied to versions.

func ParseRef

func ParseRef(str string) (Ref, error)

ParseRef docs here. In the future, would be nice to do it with zero allocations.

func (*Ref) Book

func (ref *Ref) Book(vsr *Version) *Book

TODO: deal with the nil pointers Book docs here.

func (*Ref) Chapter

func (ref *Ref) Chapter(vsr *Version) *Chapter

Chapter docs here.

func (*Ref) String

func (ref *Ref) String() string

String implements the fmt.Stringer interface.

func (*Ref) Verses

func (ref *Ref) Verses(vsr *Version) []*Verse

Verses docs here. TODO: account for when ranges are weird.

type Verse

type Verse struct {
	// Chapter is a reference to the chapter which the verse belongs to.
	Chapter *Chapter
	Number  int
	Text    string
}

Verse docs here.

func (*Verse) Ref

func (vrs *Verse) Ref() Ref

Ref docs here.

func (*Verse) String

func (vrs *Verse) String() string

String implements the fmt.Stringer interface.

type Version

type Version struct {
	Name  string
	Books []Book
}

Version docs here. TODO: probably some lazy loading in the future.

func (*Version) GetBook

func (vsr *Version) GetBook(name string) *Book

GetBook docs here. TODO: probably some fuzzyfinding in the future.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳