Class: Scripture::BibleProvider::Base
- Inherits:
-
Object
- Object
- Scripture::BibleProvider::Base
- Defined in:
- lib/scripture/bible_providers/base.rb
Overview
Public: Base class for BibleProvider. Should be inherited from and overridden.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#path_to_verse ⇒ Object
readonly
Public: Provides a Get method for the path to the verse.
-
#url ⇒ Object
readonly
Public: Provides a Get method for the url of the BibleProvider.
Instance Method Summary collapse
-
#agent ⇒ Object
Internal: A Mechanize agent to browse pages.
-
#get(verse) ⇒ Object
Public: Get a verse.
-
#get_for_display(verse) ⇒ Object
Public: Get a verse for display.
-
#initialize ⇒ Base
constructor
A new instance of Base.
-
#main_page ⇒ Object
Public: The main page of the BibleProvider.
-
#search_for(verse) ⇒ Object
Internal: Searches for the verse.
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
10 11 |
# File 'lib/scripture/bible_providers/base.rb', line 10 def initialize end |
Instance Attribute Details
#path_to_verse ⇒ Object (readonly)
Public: Provides a Get method for the path to the verse. Usually CSS Path.
8 9 10 |
# File 'lib/scripture/bible_providers/base.rb', line 8 def path_to_verse @path_to_verse end |
#url ⇒ Object (readonly)
Public: Provides a Get method for the url of the BibleProvider
6 7 8 |
# File 'lib/scripture/bible_providers/base.rb', line 6 def url @url end |
Instance Method Details
#agent ⇒ Object
Internal: A Mechanize agent to browse pages
Returns a Mechanize object
16 17 18 19 20 21 |
# File 'lib/scripture/bible_providers/base.rb', line 16 def agent @agent = Mechanize.new unless @agent @agent. = true @agent.user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:7.0.1) Gecko/20100101 Firefox/7.0.1' @agent end |
#get(verse) ⇒ Object
Public: Get a verse
verse - The verse to get
Returns the verse as a String
46 47 48 |
# File 'lib/scripture/bible_providers/base.rb', line 46 def get(verse) @verse_text = search_for(verse) end |
#get_for_display(verse) ⇒ Object
Public: Get a verse for display. Should be overridden for things such as formatting.
verse - The verse to get and display
Returns the verse to display
56 57 58 |
# File 'lib/scripture/bible_providers/base.rb', line 56 def get_for_display(verse) get(verse) end |
#main_page ⇒ Object
Public: The main page of the BibleProvider
Returns the agent on the main page
26 27 28 |
# File 'lib/scripture/bible_providers/base.rb', line 26 def main_page agent.get(@url) end |
#search_for(verse) ⇒ Object
Internal: Searches for the verse. Must be overridden. May be changed to a private method. get should be used when acquiring a verse.
verse - The verse to find.
Returns the verse
37 38 39 |
# File 'lib/scripture/bible_providers/base.rb', line 37 def search_for(verse) raise NotImplementedError, "#{self.class} does not implement #{__method__}" end |