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.



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

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.



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

def book_number
  @book_number
end

Class Method Details

.find(string_id) ⇒ Object



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

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



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

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



76
77
78
79
# File 'lib/scriptura/scripture_book.rb', line 76

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

#abbr_nameObject



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

def abbr_name
  book_hash['abbr']
end

#first_chapterObject



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

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

#first_chapter_numberObject



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

def first_chapter_number
  first_chapter.number
end

#last_chapterObject



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

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

#last_chapter_numberObject



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

def last_chapter_number
  last_chapter.number
end

#nameObject



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

def name
  book_hash['name']
end

#number_of_chaptersObject



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

def number_of_chapters
  book_hash['chapters'].count
end

#string_idObject



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

def string_id
  book_hash['string_id']
end

#testamentObject



56
57
58
59
60
61
62
# File 'lib/scriptura/scripture_book.rb', line 56

def testament
  @testament = if number < 40
    Scriptura::Testament.new('Old')
  else
    Scriptura::Testament.new('New')
  end
end

#to_hashObject



64
65
66
# File 'lib/scriptura/scripture_book.rb', line 64

def to_hash
  book_hash
end

#to_sObject



72
73
74
# File 'lib/scriptura/scripture_book.rb', line 72

def to_s
  name
end