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.
- COPYRIGHT_TEXT_REGEX
Regular expression for pulling the copyright out of the Bible text
- URI
The
URI
of the API gateway
Public Class Methods
Initializes the BibleGateway
class @return [BibleGateway]
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
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
Extracts copyright tag from the Bible text @return [String]
# File lib/votd/bible_gateway.rb, line 95 def get_copyright(text) text = strip_html_quote_entities(text) text = Helper::Text.strip_html_tags(text) text.match(COPYRIGHT_TEXT_REGEX)[1] end
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
Removes copyright text from the Bible text @return [String]
# File lib/votd/bible_gateway.rb, line 109 def strip_copyright_text(text) text.gsub(COPYRIGHT_TEXT_REGEX, '') end
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