Bible_ex - An Elixir package that parses strings for Bible references

bible_ex - An Elixir package that parses strings for Bible references.

This is a port of the Dart package GitHub - joshpetit/reference_parser: Parse strings for bible references to Elixir.

An Elixir package that parses strings for bible references. You can parse single references or multiple references from a string in a variety of formats.

Parsing References

use the parse_references function to retrieve a single reference:

alias BibleEx.RefParser
refs = RefParser.parse_references("I like Mat 2:4-10 and 1john 3:16")

This will return two reference objects, one describing “Matthew 2:4-10” and the other “1 John 3:16”

Note: The word ‘is’ will be parsed as the book of Isaiah.

[
  %BibleEx.Reference{
    book: "Matthew",
    book_names: %{abbr: "MAT", name: "Matthew", osis: "Matt", short: "Mt"},
    book_number: 40,
    reference: "Matthew 2:4-10",
    reference_type: :verse_range,
    start_chapter: %BibleEx.Chapter{
      ...
    }
  ...
  },
  %BibleEx.Reference{
  book: "1 John",
  book_names: %{abbr: "1JO", name: "1 John", osis: "1John", short: "1 Jn"},
  book_number: 62,
  reference: "1 John 3:16",
  reference_type: :verse,
  start_chapter: %BibleEx.Chapter{
    ...
  }
  ...
]

Objects and References

Reference

Reference objects are the broadest kind of reference.
You can directly construct one by following this format:

genesis_ref = Reference.new(book: "Genesis", start_chapter: 2, start_verse: 3, end_chapter: 4, end_verse: 5)
%BibleEx.Reference{
  book: "Genesis",
  book_names: %{abbr: "GEN", name: "Genesis", osis: "Gen", short: "Gn"},
  book_number: 1,
  reference: "Genesis 2:3 - 4:5",
  reference_type: :chapter_range,
  start_chapter: %BibleEx.Chapter{
    ...
  }
}

Their most important fields are these:

genesis_ref.reference # The string representation (osis_reference, short_reference, and abbr also available)
genesis_ref.start_verse_number
genesis_ref.end_verse_number
genesis_ref.start_chapter_number
genesis_ref.end_chapter_number
genesis_ref.reference_type # :verse, :chapter, :verse_range, :chapter_range, :book

Based on what is passed in, the constructor will figure out
certain fields. For example, if you were to construct Reference('James')
the last chapter and verse numbers in James will be initialized accordingly.

There is more to the library including Chapter and Verse structs. Please take a look at the HexDocs.

8 Likes

Hello sir. Thanks for this lib. I have a question.

  1. Does it need to connect to apis online to retrieve info?

  2. What Bible version it uses?

  3. Can i use it to build a web-based bible app where i can create UI for users to choose book, chapter, verses and display those verses?

Ty

  1. No, it’s just a text parser.

  2. It’s not concerned with any bible version. It just extracts the book, chapter and verse structure.

  3. Yes for sure.

1 Like

Thank you sir. I’ll try this lib and see what i can create with it. :heart:

1 Like