Class: Scriptura::ScriptureBook

Inherits:
Object
  • Object
show all
Defined in:
lib/scriptura/scripture_book.rb

Defined Under Namespace

Classes: DoesNotExist

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number) ⇒ ScriptureBook

Returns a new instance of ScriptureBook.



8
9
10
11
12
# File 'lib/scriptura/scripture_book.rb', line 8

def initialize(number)
  fail ArgumentError, 'book number cannot be converted to an integer' unless number.respond_to?(:to_i)
  fail DoesNotExist, 'Book number should be within 1-66' unless (1..66).cover?(number.to_i)
  @book_number = number.to_i
end

Instance Attribute Details

#book_numberObject (readonly) Also known as: number

Returns the value of attribute book_number.



5
6
7
# File 'lib/scriptura/scripture_book.rb', line 5

def book_number
  @book_number
end

Class Method Details

.find(string_id) ⇒ Object



20
21
22
23
24
# File 'lib/scriptura/scripture_book.rb', line 20

def self.find(string_id)
  hash = Scripture.find_book_hash(:string_id, string_id)
  fail DoesNotExist, "Book by the string_id #{string_id} was not found! Check if there was a spelling error.. or try initializing it with a book number" if hash.nil?
  new(hash['number'])
end

.find_by_name(name) ⇒ Object



14
15
16
17
18
# File 'lib/scriptura/scripture_book.rb', line 14

def self.find_by_name(name)
  hash = Scripture.find_book_hash(:name, name)
  fail DoesNotExist, "Book by the name #{name} was not found! Check if there was a spelling error.. or try initializing it with a book number" if hash.nil?
  new(hash['number'])
end

Instance Method Details

#==(other) ⇒ Object



66
67
68
69
# File 'lib/scriptura/scripture_book.rb', line 66

def ==(other)
  return false unless other.is_a?(ScriptureBook)
  book_number == other.book_number
end

#abbr_nameObject



30
31
32
# File 'lib/scriptura/scripture_book.rb', line 30

def abbr_name
  book_hash['abbr']
end

#first_chapterObject



38
39
40
# File 'lib/scriptura/scripture_book.rb', line 38

def first_chapter
  @first_chapter ||= ScriptureChapter.new(number, 1)
end

#first_chapter_numberObject



46
47
48
# File 'lib/scriptura/scripture_book.rb', line 46

def first_chapter_number
  first_chapter.number
end

#last_chapterObject



42
43
44
# File 'lib/scriptura/scripture_book.rb', line 42

def last_chapter
  @last_chapter ||= ScriptureChapter.new(number, number_of_chapters)
end

#last_chapter_numberObject



50
51
52
# File 'lib/scriptura/scripture_book.rb', line 50

def last_chapter_number
  last_chapter.number
end

#nameObject



26
27
28
# File 'lib/scriptura/scripture_book.rb', line 26

def name
  book_hash['name']
end

#number_of_chaptersObject



34
35
36
# File 'lib/scriptura/scripture_book.rb', line 34

def number_of_chapters
  book_hash['chapters'].count
end

#string_idObject



58
59
60
# File 'lib/scriptura/scripture_book.rb', line 58

def string_id
  book_hash['string_id']
end

#to_hashObject



54
55
56
# File 'lib/scriptura/scripture_book.rb', line 54

def to_hash
  book_hash
end

#to_sObject



62
63
64
# File 'lib/scriptura/scripture_book.rb', line 62

def to_s
  name
end