New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

bible_ref

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bible_ref

  • 1.9.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

BibleRef

This small Rubygem does its best at taking a user-input string like "john 3:16" and turning it into something useful for querying a database (this is how we use it in bible_api).

Usage

ref = BibleRef::Reference.new('jn 3:16')
# #<BibleRef::Reference:0x000001020f7000 @reference="jn 3:16", @details={:book=>"jn", :refs=>{:chapter=>3, :verse=>16}}>

ref.valid?
# true

ref.book_id
# "JHN"

ref.normalize
# "John 3:16"

Ranges

Call #ranges to get from/to pairs of verses.

BibleRef::Reference.new('john 3:16').ranges
# [
#   [{ book: 'JHN', chapter: 3, verse: 16 },
#    { book: 'JHN', chapter: 3, verse: 16 }]
# ]

BibleRef::Reference.new('Romans 12:1,3-4 & 13:2-4,7-8').ranges
# [
#   [{ book: 'ROM', chapter: 12, verse: 1 },
#    { book: 'ROM', chapter: 12, verse: 1 }],
#   [{ book: 'ROM', chapter: 12, verse: 3 },
#    { book: 'ROM', chapter: 12, verse: 4 }],
#   [{ book: 'ROM', chapter: 13, verse: 2 },
#    { book: 'ROM', chapter: 13, verse: 4 }],
#   [{ book: 'ROM', chapter: 13, verse: 7 },
#    { book: 'ROM', chapter: 13, verse: 8 }]
# ]

You can then take this and turn it into a few small SQL queries like this:

verses = ranges.map do |from_ref, to_ref|
  first = DB['select id from verses where book = :book and chapter = :chapter and verse = :verse limit 1', from_ref].first
  last  = DB['select id from verses where book = :book and chapter = :chapter and verse = :verse limit 1', to_ref].first
  DB['select * from verses where id between ? and ?', first['id'], last['id']]
end

Single-Chapter Book Matching

Passing single_chapter_book_matching keyword to Reference changes how single-chapter books are handled. It affects how something like Jude 1 is parsed:

settinginputresult
:special (default)jude 1single verse of Jude 1:1
:indifferentjude 1whole chapter of Jude

While the default of :special seems to match what most people expect, using the :indifferent setting will make jude 1 behave the same as something like john 1 -- both will return the entire chapter.

BibleRef::Reference.new('jude 1').ranges
# [
#   [{ book: 'JUD', chapter: 1, verse: 1 },
#    { book: 'JUD', chapter: 1, verse: 1 }]
# ]

BibleRef::Reference.new('jude 1', single_chapter_book_matching: :indifferent).ranges
# [
#   [{ book: 'JUD', chapter: 1 },
#    { book: 'JUD', chapter: 1 }]
# ]

Copyright Tim Morgan. Licensed MIT.

FAQs

Package last updated on 02 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc