Class: Scripture::BibleProvider::Base

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

Overview

Public: Base class for BibleProvider. Should be inherited from and overridden.

Direct Known Subclasses

PreachingCentral

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

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_verseObject (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

#urlObject (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

#agentObject

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.follow_meta_refresh = 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_pageObject

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

Raises:

  • (NotImplementedError)


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