View Source BibleEx.RefParser (bible_ex v0.2.1)
Parses general strings for Bible references.
This module scans arbitrary text for Bible references in a variety of
formats (full book names, abbreviations, ranges, etc.) and returns
%BibleEx.Reference{} structs.
Link to this section Summary
Functions
Parses a binary for all Bible references and returns a list of %BibleEx.Reference{}.
Link to this section Functions
Parses a binary for all Bible references and returns a list of %BibleEx.Reference{}.
The parser supports:
- Full book names with chapter and verse.
- Common abbreviations and variants (e.g.
Matt,Jn,1 Tim). - Same-chapter verse ranges (e.g.
John 3:16-18). - Cross-chapter ranges (e.g.
John 3:16-4:3). - Dot separators with optional spaces (e.g.
James 1 . 2 - 2 . 4). - Bare book names (e.g.
Isaiah,1 Timothy) which are normalized byBibleEx.Reference.
examples
Examples
iex> alias BibleEx.RefParser
iex> [ref] = RefParser.parse_references("John 3:16")
iex> ref.book
"John"
iex> ref.start_chapter
3
iex> ref.start_verse
16
iex> refs = RefParser.parse_references("Matt 2:4 and James 5:1-5")
iex> Enum.map(refs, & &1.book)
["Matthew", "James"]
iex> Enum.map(refs, & &1.reference_type) |> Enum.sort()
[:verse, :verse_range]
iex> [ref] = RefParser.parse_references("James 1 . 2 - 2 . 4")
iex> ref.book
"James"
iex> {ref.start_chapter, ref.start_verse, ref.end_chapter, ref.end_verse}
{1, 2, 2, 4}
iex> [ref] = RefParser.parse_references("is. 1 Timothy 6, 1.")
iex> ref.book
"1 Timothy"
iex> {ref.start_chapter, ref.start_verse}
{6, 1}