monty5811/elm-bible/2.0.2

NOTE: the latest version is 2.1.0

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:

  • Genesis 1
  • Genesis 1:1
  • Genesis 1:1-20
  • Genesis 1:20-2:24
  • Genesis 1-5
  • Genesis 1 - Exodus 5
  • Genesis 1:1 - Exodus 5:20
  • Genesis 1:1 - Exodus 5
  • Genesis 1 - Exodus 5:20

Formatting

format : Reference -> String

Get a formatted String from a Reference.

Some example outputs:

  • Genesis 1:1
  • Genesis 1:1-11
  • Genesis 1:1 - 12:2
  • Genesis 1:1 - Exodus 2:4

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
-> { start : Int
, end : Int
}

Convert a reference to an encoded representation.

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

Get the name of the book the reference starts with.

Get the name of the book the reference ends with.

Get the chapter the reference starts with.

Get the chapter the reference ends with.

Get the verse the reference starts with.

Get the verse the reference ends with.

Types

An opaque type to represent a Bible reference.