Class: Scriptura::ScriptureChapter

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

Defined Under Namespace

Classes: DoesNotExist

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(book_number, chapter_number) ⇒ ScriptureChapter

Returns a new instance of ScriptureChapter.



9
10
11
12
13
14
15
# File 'lib/scriptura/scripture_chapter.rb', line 9

def initialize(book_number, chapter_number)
  @scripture_book = ScriptureBook.new(book_number)
  fail ArgumentError, 'chapter number cannot be converted to an integer' unless chapter_number.respond_to?(:to_i)
  fail 'book number should be within 1-66' unless (1..66).cover?(book_number.to_i)
  @chapter_number = chapter_number.to_i
  fail DoesNotExist, 'chapter does not exist' if chapter_hash.nil?
end

Instance Attribute Details

#chapter_numberObject (readonly) Also known as: number

Returns the value of attribute chapter_number.



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

def chapter_number
  @chapter_number
end

#scripture_bookObject (readonly)

Returns the value of attribute scripture_book.



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

def scripture_book
  @scripture_book
end

Instance Method Details

#==(other) ⇒ Object



41
42
43
44
45
# File 'lib/scriptura/scripture_chapter.rb', line 41

def ==(other)
  return false unless other.is_a?(ScriptureChapter)
  scripture_book == other.scripture_book &&
    chapter_number == other.chapter_number
end

#first_verseObject



21
22
23
# File 'lib/scriptura/scripture_chapter.rb', line 21

def first_verse
  @first_verse = ScriptureVerse.new(scripture_book.number, number, 1)
end

#first_verse_numberObject



29
30
31
# File 'lib/scriptura/scripture_chapter.rb', line 29

def first_verse_number
  first_verse.number
end

#last_verseObject



25
26
27
# File 'lib/scriptura/scripture_chapter.rb', line 25

def last_verse
  @first_verse = ScriptureVerse.new(scripture_book.number, number, number_of_verses)
end

#last_verse_numberObject



33
34
35
# File 'lib/scriptura/scripture_chapter.rb', line 33

def last_verse_number
  last_verse.number
end

#number_of_versesObject



17
18
19
# File 'lib/scriptura/scripture_chapter.rb', line 17

def number_of_verses
  chapter_hash['verses']
end

#to_sObject



37
38
39
# File 'lib/scriptura/scripture_chapter.rb', line 37

def to_s
  "#{scripture_book} #{@chapter_number}"
end