Class: Votd::Base
- Inherits:
-
Object
- Object
- Votd::Base
- Defined in:
- lib/votd/base.rb
Overview
This is the base class that all Votd lookup modules inherit from. Child classes should override the #get_votd method to implement their specific lookup function. Errors during fetch are raised as FetchError and reported via logger and on_error.
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_BIBLE_TEXT =
The default Bible text to use. This is used in case of an error retrieving the VotD from a remote server
"For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life."- DEFAULT_BIBLE_REFERENCE =
The default Bible reference to use. This is used in case of an error retrieving the VotD from a remote server
"John 3:16"- DEFAULT_BIBLE_VERSION =
The default Bible version to use if none is given and no other default is provided
"KJV"- DEFAULT_BIBLE_VERSION_NAME =
The default Bible version name to use if none is given and no other default is provided
"King James Version"- DEFAULT_LINK =
The default link to use if none is provided by the VotD service
"https://www.biblegateway.com/passage/?search=John+3%3A16&version=KJV"
Instance Attribute Summary collapse
-
#copyright ⇒ String
readonly
Any copyright information supplied by VotD provider.
-
#date ⇒ String
readonly
The date the Verse was retrieved.
-
#link ⇒ String
readonly
A URL link to the verse on the corresponding Bible service.
-
#reference ⇒ String
readonly
The scripture reference.
-
#text ⇒ String
readonly
The full bible passage.
-
#version ⇒ String
(also: #translation)
readonly
The bible translation acronym used for this VotD.
-
#version_name ⇒ String
(also: #translation_name)
readonly
The bible translation name used for this VotD.
Instance Method Summary collapse
-
#custom_html {|votd| ... } ⇒ Object
Overrides the #to_html method with your own custom HTML.
-
#custom_text {|votd| ... } ⇒ Object
Overrides the #to_text with your own custom text.
-
#initialize ⇒ Base
constructor
Initializes the class and retrieves the verse of the day.
-
#to_html ⇒ String
Returns the Verse of the Day formatted as HTML.
-
#to_text ⇒ String
(also: #to_s)
Returns the Verse of the Day formatted as plain text.
Constructor Details
#initialize ⇒ Base
Initializes the class and retrieves the verse of the day.
70 71 72 73 74 75 |
# File 'lib/votd/base.rb', line 70 def initialize @date = Date.today @custom_html = nil @custom_text = nil get_votd end |
Instance Attribute Details
#copyright ⇒ String (readonly)
Returns any copyright information supplied by VotD provider.
41 42 43 |
# File 'lib/votd/base.rb', line 41 def copyright @copyright end |
#date ⇒ String (readonly)
Returns the date the Verse was retrieved.
24 25 26 |
# File 'lib/votd/base.rb', line 24 def date @date end |
#link ⇒ String (readonly)
Returns A URL link to the verse on the corresponding Bible service.
47 48 49 |
# File 'lib/votd/base.rb', line 47 def link @link end |
#reference ⇒ String (readonly)
Returns the scripture reference.
18 19 20 |
# File 'lib/votd/base.rb', line 18 def reference @reference end |
#text ⇒ String (readonly)
Returns the full bible passage.
12 13 14 |
# File 'lib/votd/base.rb', line 12 def text @text end |
#version ⇒ String (readonly) Also known as: translation
Returns the bible translation acronym used for this VotD.
29 30 31 |
# File 'lib/votd/base.rb', line 29 def version @version end |
#version_name ⇒ String (readonly) Also known as: translation_name
Returns the bible translation name used for this VotD.
35 36 37 |
# File 'lib/votd/base.rb', line 35 def version_name @version_name end |
Instance Method Details
#custom_html {|votd| ... } ⇒ Object
118 119 120 121 122 123 124 |
# File 'lib/votd/base.rb', line 118 def custom_html if block_given? @custom_html = yield(self) else raise Votd::VotdError, "You must use a block with this method" end end |
#custom_text {|votd| ... } ⇒ Object
153 154 155 156 157 158 159 |
# File 'lib/votd/base.rb', line 153 def custom_text if block_given? @custom_text = yield(self) else raise Votd::VotdError, "You must use a block with this method" end end |
#to_html ⇒ String
Returns the Verse of the Day formatted as HTML. e.g.
For by grace you are saved through faith...
Ephesians 2:8-9 (NETBible)
This should provide sufficient hooks to style the CSS. If this is not sufficient, you can build the HTML by hand using the individual data, or use the #custom_html method to override the HTML format.
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/votd/base.rb', line 89 def to_html default_html = [ %(<p class="votd-text">#{@text}</p>), "<p>", %(<span class="votd-reference"><strong>#{@reference}</strong></span>), %(<span class="votd-version"><em>(#{@version})</em></span>), "</p>", "" ].join("\n") @custom_html ||= default_html end |
#to_text ⇒ String Also known as: to_s
Returns the Verse of the Day formatted as plain text. e.g. For God so loved the world... -- John 3:16 (KJV)
You can override this formatting with the #custom_text method.
131 132 133 |
# File 'lib/votd/base.rb', line 131 def to_text @custom_text ||= "#{@text} -- #{@reference} (#{@version})" end |