Class: Scriptura::ScriptureReference
- Inherits:
-
Object
- Object
- Scriptura::ScriptureReference
- Defined in:
- lib/scriptura/scripture_reference.rb
Instance Attribute Summary collapse
-
#end_verse ⇒ Object
readonly
Returns the value of attribute end_verse.
-
#start_verse ⇒ Object
readonly
Returns the value of attribute start_verse.
Instance Method Summary collapse
-
#initialize(start_verse, end_verse) ⇒ ScriptureReference
constructor
A new instance of ScriptureReference.
- #spans_entire_book? ⇒ Boolean
- #spans_entire_chapter? ⇒ Boolean
- #spans_single_verse? ⇒ Boolean
- #to_s ⇒ Object
- #within_same_book? ⇒ Boolean
- #within_same_chapter? ⇒ Boolean
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_verse ⇒ Object (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_verse ⇒ Object (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
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
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
33 34 35 |
# File 'lib/scriptura/scripture_reference.rb', line 33 def spans_single_verse? start_verse == end_verse end |
#to_s ⇒ Object
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
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
17 18 19 |
# File 'lib/scriptura/scripture_reference.rb', line 17 def within_same_chapter? start_verse.scripture_chapter == end_verse.scripture_chapter end |