Class: Scriptura::ScriptureVerse

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

Defined Under Namespace

Classes: DoesNotExist

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ ScriptureVerse

Returns a new instance of ScriptureVerse.



10
11
12
13
14
15
16
17
18
# File 'lib/scriptura/scripture_verse.rb', line 10

def initialize(*args)
  book_number, chapter_number, verse_number = extract_arguments(args)

  @scripture_chapter = ScriptureChapter.new(book_number, chapter_number)
  @scripture_book = @scripture_chapter.scripture_book
  fail ArgumentError, 'verse number cannot be converted to an integer' unless verse_number.respond_to?(:to_i)
  fail DoesNotExist, 'verse number does not exist' unless (1..@scripture_chapter.number_of_verses).cover? verse_number.to_i
  @verse_number = verse_number.to_i
end

Instance Attribute Details

#scripture_bookObject (readonly)

Returns the value of attribute scripture_book.



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

def scripture_book
  @scripture_book
end

#scripture_chapterObject (readonly)

Returns the value of attribute scripture_chapter.



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

def scripture_chapter
  @scripture_chapter
end

#verse_numberObject (readonly) Also known as: number

Returns the value of attribute verse_number.



7
8
9
# File 'lib/scriptura/scripture_verse.rb', line 7

def verse_number
  @verse_number
end

Instance Method Details

#==(other) ⇒ Object



28
29
30
31
32
33
# File 'lib/scriptura/scripture_verse.rb', line 28

def ==(other)
  return false unless other.is_a?(ScriptureVerse)
  scripture_book == other.scripture_book &&
    scripture_chapter == other.scripture_chapter &&
    verse_number == other.verse_number
end

#normalizeObject



20
21
22
# File 'lib/scriptura/scripture_verse.rb', line 20

def normalize
  scripture_book.number * 1_000_000 + scripture_chapter.number * 1000 + @verse_number
end

#to_sObject



24
25
26
# File 'lib/scriptura/scripture_verse.rb', line 24

def to_s
  "#{scripture_chapter}:#{number}"
end