class Votd::BibleGateway

Retrieves a Verse of the Day from biblegateway.com using a variety of translations.

Default translation is NIV (New International Version)

docs: www.biblegateway.com/usage/votd/docs/

version list: www.biblegateway.com/usage/linking/versionslist.php

Constants

BIBLE_VERSIONS

These are the English translations that are copyright-approved for Bible Gateway VotD as of November 2019.

Regular expression for pulling the copyright out of the Bible text

URI

The URI of the API gateway

Public Class Methods

new(version = :niv) click to toggle source

Initializes the BibleGateway class @return [BibleGateway]

Calls superclass method Votd::Base::new
# File lib/votd/bible_gateway.rb, line 48
def initialize(version = :niv)
  raise InvalidBibleVersion unless BIBLE_VERSIONS.has_key?(version)

  @version = version.to_s.upcase
  @version_number = BIBLE_VERSIONS[version][:id]
  @version_name = BIBLE_VERSIONS[version][:name]
  super()
end

Private Instance Methods

clean_text(text) click to toggle source

Cleans up the text. Removes:

- HTML quote entities
- HTML tags
- Copyright text
- Extra spaces, line breaks, etc.

@return [String]

# File lib/votd/bible_gateway.rb, line 84
def clean_text(text)
  text = strip_html_quote_entities(text)
  text = Helper::Text.strip_html_tags(text)
  text = strip_copyright_text(text)
  text.strip!
  text = Helper::Text.clean_verse_start(text)
  text = Helper::Text.clean_verse_end(text)
end
get_votd() click to toggle source

Gets the votd from the Bible Gateway RSS feed @return [String]

# File lib/votd/bible_gateway.rb, line 61
def get_votd
  uri          = "#{URI}#{@version_number}"
  feed         = Feedjira.parse(HTTParty.get(uri).body)
  entry        = feed.entries.first
  cleaned_text = clean_text(entry.content)

  @reference   = entry.title
  @link        = entry.entry_id
  @text        = cleaned_text
  @copyright   = get_copyright(entry.content)
rescue => e
  # use default info for VotD
  set_defaults
  #raise e
  # @todo Add logging
end
strip_html_quote_entities(text) click to toggle source

Removes HTML quote entities added by BibleGateway @return [String]

# File lib/votd/bible_gateway.rb, line 103
def strip_html_quote_entities(text)
  text.gsub(/&.dquo;/, '')
end