Class: Scriptura::ScriptureReference

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_verse, end_verse) ⇒ ScriptureReference

Returns a new instance of ScriptureReference.



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

def initialize(start_verse, end_verse)
  @start_verse = start_verse
  @end_verse = end_verse
end

Instance Attribute Details

#end_verseObject (readonly)

Returns the value of attribute end_verse.



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

def end_verse
  @end_verse
end

#start_verseObject (readonly)

Returns the value of attribute start_verse.



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

def start_verse
  @start_verse
end

Instance Method Details

#spans_entire_book?Boolean

Returns:

  • (Boolean)


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

def spans_entire_book?
  scripture_book = start_verse.scripture_book
  start_verse == scripture_book.first_chapter.first_verse &&
    end_verse == scripture_book.last_chapter.last_verse
end

#spans_entire_chapter?Boolean

Returns:

  • (Boolean)


27
28
29
30
31
# File 'lib/scriptura/scripture_reference.rb', line 27

def spans_entire_chapter?
  scripture_chapter = start_verse.scripture_chapter
  start_verse == scripture_chapter.first_verse &&
    end_verse == scripture_chapter.last_verse
end

#spans_single_verse?Boolean

Returns:

  • (Boolean)


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

def spans_single_verse?
  start_verse == end_verse
end

#to_sObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/scriptura/scripture_reference.rb', line 37

def to_s
  case
  when spans_entire_book?
    start_verse.scripture_book.to_s
  when spans_entire_chapter?
    start_verse.scripture_chapter.to_s
  when spans_single_verse?
    start_verse.to_s
  when within_same_chapter?
    "#{start_verse}#{end_verse.number}"
  when within_same_book?
    "#{start_verse}#{end_verse.scripture_chapter.number}:#{end_verse.number}"
  else
    "#{start_verse}#{end_verse}"
  end
end

#within_same_book?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/scriptura/scripture_reference.rb', line 13

def within_same_book?
  start_verse.scripture_book == end_verse.scripture_book
end

#within_same_chapter?Boolean

Returns:

  • (Boolean)


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

def within_same_chapter?
  start_verse.scripture_chapter == end_verse.scripture_chapter
end