class ActsAsScriptural::Bible
Attributes
indexhash[RW]
namehash[RW]
Public Class Methods
new()
click to toggle source
# File lib/acts_as_scriptural/bible.rb, line 7 def initialize # two lookup tables...not too DRY @namehash = Hash.new @indexhash = Hash.new import_from_file end
Public Instance Methods
book_names()
click to toggle source
# File lib/acts_as_scriptural/bible.rb, line 14 def book_names @namehash.map{|k,v| v.name} end
chapter_exists?(book_index, chapter_number)
click to toggle source
# File lib/acts_as_scriptural/bible.rb, line 18 def chapter_exists?(book_index, chapter_number) @indexhash[book_index] && chapter_number.between?(1, @indexhash[book_index].num_chapters) end
chapters_in_book(book_index)
click to toggle source
# File lib/acts_as_scriptural/bible.rb, line 23 def chapters_in_book(book_index) @indexhash[book_index].num_chapters end
Private Instance Methods
import_from_file()
click to toggle source
# File lib/acts_as_scriptural/bible.rb, line 29 def import_from_file datafile = File.dirname(__FILE__) + "/../../data/acts_as_scriptural/english.txt" File.readlines(datafile).each do |line| book_name, book_index, num_chapters = line.chomp.split(',') book = ActsAsScriptural::Book.new(book_name, book_index.to_i, num_chapters.to_i) @namehash[book_name] = book @indexhash[book_index.to_i] = book end end