Class: Bible::NABLookup

Inherits:
Object
  • Object
show all
Defined in:
lib/bible/lookup/nab.rb

Constant Summary collapse

@@books =
{}

Class Method Summary collapse

Class Method Details

.get_ref(book, chapter = nil, verse = nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/bible/lookup/nab.rb', line 23

def self.get_ref(book, chapter = nil, verse = nil)
  # TODO: Handle nil chapter
  text = ((@@books[book] ||= {})[chapter] ||= open(getURL(book, chapter)).gets(nil))
  scanner = StringScanner.new(text)
  scanner.skip_until(/<DL>/)
  scanner = StringScanner.new(scanner.check_until(/<\/DL>/))
  unless verse.nil?
    if scanner.skip_until(/<A.*?NAME="v#{verse}".*?>.*?#{verse}.*?<\/A>/)
      scanner = StringScanner.new(scanner.check_until(/<\/DD>/))
    else
      return ""
    end
  end

  scanner.rest.strip.gsub(/<SUP>.*?<\/SUP>/im, "").gsub(/<.*?>/im, "")
end

.getURL(book, chapter = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/bible/lookup/nab.rb', line 8

def self.getURL(book, chapter = nil)
  raise "chapter cannot be nil" if chapter.nil?
  b = book.to_s.gsub(" ", "").downcase
  case Bible::Books[book]
  when Bible::Books["Song of Solomon".to_sym]
    "http://www.usccb.org/nab/bible/songs/song#{chapter.to_s}.htm"
  when Bible::Books[:Philemon], Bible::Books[:Obadiah], Bible::Books["2 John".to_sym], Bible::Books["3 John".to_sym], Bible::Books[:Jude]
    "http://www.usccb.org/nab/bible/#{b}/#{b}.htm"
  when Bible::Books[:Psalms]
    "http://www.usccb.org/nab/bible/#{b}/psalm#{chapter.to_s}.htm"
  else
    "http://www.usccb.org/nab/bible/#{b}/#{b}#{chapter.to_s}.htm"
  end
end