Class: Scripture::BibleProvider::PreachingCentral

Inherits:
Base
  • Object
show all
Includes:
HTTParty
Defined in:
lib/scripture/bible_providers/preaching_central.rb

Overview

Public: Interact with api.preachingcentral.com to provide bible verses

Examples

@bible_provider = Scripture::BibleProvider::PreachingCentral.new
@bible_provider.get_for_display('John 3:16')
# => "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."

Instance Attribute Summary

Attributes inherited from Base

#path_to_verse, #url

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#agent, #main_page

Constructor Details

#initializePreachingCentral

Public: Initialize the object and set the url



18
19
20
# File 'lib/scripture/bible_providers/preaching_central.rb', line 18

def initialize
  @url = 'http://api.preachingcentral.com/'
end

Class Method Details

.format(verse) ⇒ Object

Internal: Format a verse

verse - The verse to format

Returns the formatted verse



70
71
72
# File 'lib/scripture/bible_providers/preaching_central.rb', line 70

def self.format(verse)
  verse.gsub(/\n/, '<br />')
end

.format_for_display(verse) ⇒ Object

Internal: Format a verse for display

verse - The verse to format

Returns the formatted verse



79
80
81
# File 'lib/scripture/bible_providers/preaching_central.rb', line 79

def self.format_for_display(verse)
  verse.gsub('<br />', "\n")
end

Instance Method Details

#get(verse) ⇒ Object

Public: Get a verse

verse - The verse to get

Returns the verse formatted with self.format



52
53
54
# File 'lib/scripture/bible_providers/preaching_central.rb', line 52

def get(verse)
  self.class.format(super)
end

#get_for_display(verse) ⇒ Object

Public: Get a verse to display

verse - The verse to get

Returns the verse formatted with self.format_for_display



61
62
63
# File 'lib/scripture/bible_providers/preaching_central.rb', line 61

def get_for_display(verse)
  self.class.format_for_display(super)
end

#search_for(verse) ⇒ Object

Internal: Search for a verse

verse - A string containing the verse reference

Returns the verse content



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/scripture/bible_providers/preaching_central.rb', line 27

def search_for(verse)
  @query = {
    "passage" => verse
  }

  @results = self.class.get("#{@url}bible.php?", :query => @query)

  @item = @results.parsed_response['bible']['range']['item']

  if @item.is_a? Array
    @text = @item.map do |item| 
      "#{item['verse']} #{item['text']} \n"
    end.join('')
  else
    @text = @item['text']
  end

  @text
end