monty5811 / elm-bible / Bible

A library for working with Bible references.

Parsing

fromString : String -> Result String Reference

Attempt to convert a String into a Reference.

The following formats should work:

Formatting

format : Reference -> String

Get a formatted String from a Reference.

Some example outputs:

Encoding

It may be useful to have a unique, compact representation of a reference for storage, searching, sorting, etc.

An easy way to achieve this is to convert the start and end of the reference to an Int. These integers can then be stored in a database, sorted, checked for intersections to do searches, etc.

The encoding process is as follows:

(1000000 * Book.toInt book) + (1000 * chapter) + verse

This results in an Int with the following structure

16001001
--===___
 | |  |
 | |  |
 | |  |--- Zero padded verse number
 | |------ Zero padded chapter number
 |-------- Book number

encode : Reference -> { start : Basics.Int, end : Basics.Int }

Convert a reference to an encoded representation.

(fromString "Gen 1:1 - Rev 5") |> Result.map encode)
    == Ok {start = 1001001, end = 66005014}

decode : { start : Basics.Int, end : Basics.Int } -> Result String Reference

Attempt to convert an encoded value to a reference.

Lower Level Parts

These functions may be useful if you want to build your own formatter, or something else.

toStartBookString : Reference -> String

Get the name of the book the reference starts with.

toEndBookString : Reference -> String

Get the name of the book the reference ends with.

toStartChapter : Reference -> Basics.Int

Get the chapter the reference starts with.

toEndChapter : Reference -> Basics.Int

Get the chapter the reference ends with.

toStartVerse : Reference -> Basics.Int

Get the verse the reference starts with.

toEndVerse : Reference -> Basics.Int

Get the verse the reference ends with.

Types


type Reference

An opaque type to represent a Bible reference.