Class: Votd::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/votd/base.rb

Overview

This is the base class that all Votd lookup modules inherit from. It provides default values for the Votd in the event of lookup failure. Child classes should override the #get_votd method to implement their specific lookup function.

Direct Known Subclasses

BibleGateway, ESVBible, NetBible

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"
"https://www.biblegateway.com/passage/?search=John+3%3A16&version=KJV"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Initializes the class and retrieves the verse of the day.



69
70
71
72
73
74
75
76
77
78
# File 'lib/votd/base.rb', line 69

def initialize
  @text        = ""
  @reference   = ""
  @copyright   = nil
  @date        = Date.today
  @custom_html = nil
  @custom_text = nil
  @link        = nil
  get_votd
end

Instance Attribute Details

Returns any copyright information supplied by VotD provider.

Examples:

votd.copyright # "Brought to you by BibleGateway.com. Copyright (C) . All Rights Reserved."

Returns:

  • (String)

    any copyright information supplied by VotD provider



41
42
43
# File 'lib/votd/base.rb', line 41

def copyright
  @copyright
end

#dateString (readonly)

Returns the date the Verse was retrieved.

Examples:

votd.date  # "2012-03-24"

Returns:

  • (String)

    the date the Verse was retrieved



24
25
26
# File 'lib/votd/base.rb', line 24

def date
  @date
end

Returns A URL link to the verse on the corresponding Bible service.

Examples:

votd.link  # "https://www.biblegateway.com/passage/?search=Colossians+3%3A16&version=NIV"

Returns:

  • (String)

    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

#referenceString (readonly)

Returns the scripture reference.

Examples:

votd.reference  # "Ephesians 2:8-9"

Returns:

  • (String)

    the scripture reference.



18
19
20
# File 'lib/votd/base.rb', line 18

def reference
  @reference
end

#textString (readonly)

Returns the full bible passage.

Examples:

votd.text  # "For by grace you are saved through faith..."

Returns:

  • (String)

    the full bible passage



12
13
14
# File 'lib/votd/base.rb', line 12

def text
  @text
end

#versionString (readonly) Also known as: translation

Returns the bible translation acronym used for this VotD.

Examples:

votd.version  # "NIV"

Returns:

  • (String)

    the bible translation acronym used for this VotD



29
30
31
# File 'lib/votd/base.rb', line 29

def version
  @version
end

#version_nameString (readonly) Also known as: translation_name

Returns the bible translation name used for this VotD.

Examples:

votd.version_name  # "New International Version"

Returns:

  • (String)

    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

Overrides the #to_html method with your own custom HTML. Use a block to specify your custom HTML. This returns the custom formatted HTML, or you can call the #to_html method when ready and your custom HTML will be output.

Examples:

votd.custom_html do |votd|
  "<p>#{votd.reference} - #{votd.text} (#{votd.version})</p>"
end

# outputs:
# <p>John 3:16 - For God so loved... (KJV)</p>

Yields:

  • (votd)

    the VotD itself

Yield Parameters:

  • votd (Base)

    the VotD itself

Yield Returns:

  • (String)

    the VotD formatted as custom HTML

Raises:

  • (VotdError)

    when called without block format



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

Overrides the #to_text with your own custom text. Use a block to specify your custom text. This returns the custom formatted text, or you can call the #to_text method when ready, and your custom text will be output.

Examples:

votd.custom_text do |votd|
  "#{votd.reference}|#{votd.text}|#{votd.version}"
end

# outputs:
John 3:16|For God so loved...|(KJV)

Yields:

  • (votd)

    the VotD itself

Yield Parameters:

  • votd (Base)

    the VotD itself

Yield Returns:

  • (String)

    the VotD formatted as custom text

Raises:

  • (VotdError)

    when called without block format



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_htmlString

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.

Returns:

  • (String)

    the VotD formatted as HTML



92
93
94
95
96
97
98
99
# File 'lib/votd/base.rb', line 92

def to_html
  default_html =  "<p class=\"votd-text\">#{@text}</p>\n"
  default_html << "<p>\n"
  default_html << "<span class=\"votd-reference\"><strong>#{@reference}</strong></span>\n"
  default_html << "<span class=\"votd-version\"><em>(#{@version})</em></span>\n"
  default_html << "</p>\n"
  @custom_html ||= default_html
end

#to_textString 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.

Returns:

  • (String)

    the VotD formatted as plain text



131
132
133
# File 'lib/votd/base.rb', line 131

def to_text
  @custom_text ||= "#{@text} -- #{@reference} (#{@version})"
end