class BibleBot::Book
Represents one of the 66 books in the bible (Genesis - Revelation). You should never need to initialize a Book
, they are initialized in {Bible}.
Attributes
abbreviation[R]
chapters[R]
id[R]
name[R]
regex[R]
testament[R]
Public Class Methods
find_by_id(id)
click to toggle source
Find by the Book
ID defined in {Bible}.
@param id [Integer] @return [Book]
# File lib/bible_bot/book.rb, line 29 def self.find_by_id(id) Bible.books.find { |book| book.id == id } end
find_by_name(name)
click to toggle source
Uses the same Regex pattern to match as we use in {Reference.parse}. So this supports the same book name abbreviations.
@param name [String] @return [Book] @example
Book.find_by_name("Genesis")
# File lib/bible_bot/book.rb, line 19 def self.find_by_name(name) return nil if name.nil? || name.strip == "" Bible.books.find { |book| name.match(Regexp.new('\b'+book.regex+'\b', Regexp::IGNORECASE)) } end
new(id:, name:, abbreviation:, regex:, chapters: [] , testament:)
click to toggle source
# File lib/bible_bot/book.rb, line 33 def initialize(id:, name:, abbreviation:, regex:, chapters: [] , testament:) @id = id @name = name @abbreviation = abbreviation @regex = regex @chapters = chapters @testament = testament end
Public Instance Methods
end_verse()
click to toggle source
@return [Verse]
# File lib/bible_bot/book.rb, line 68 def end_verse @last_verse ||= Verse.from_id( "#{id}#{chapters.length.to_s.rjust(3, '0')}#{chapters.last.to_s.rjust(3, '0')}".to_i ) end
formatted_name()
click to toggle source
@return [String]
# File lib/bible_bot/book.rb, line 43 def formatted_name case name when 'Psalms' then 'Psalm' else name end end
next_book()
click to toggle source
@return [Book, nil]
# File lib/bible_bot/book.rb, line 75 def next_book return @next_book if defined? @next_book @next_book = Book.find_by_id(id + 1) end
reference()
click to toggle source
A reference containing the entire book @return [Reference]
# File lib/bible_bot/book.rb, line 58 def reference @reference ||= Reference.new(start_verse: start_verse, end_verse: end_verse) end
single_chapter?()
click to toggle source
Single chapter book like Jude @return [Boolean]
# File lib/bible_bot/book.rb, line 52 def single_chapter? chapters.length == 1 end
start_verse()
click to toggle source
@return [Verse]
# File lib/bible_bot/book.rb, line 63 def start_verse @first_verse ||= Verse.from_id("#{id}001001".to_i) end