Class: WCC::Scripture::Esv::Reference

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/wcc/scripture/esv.rb

Constant Summary collapse

SINGLE_CHAPTER_BOOK_REGEX =
/^(obadiah|philemon|2 john|3 john|jude)$/i.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pericope, book_only = false) ⇒ Reference

Returns a new instance of Reference.



21
22
23
24
# File 'lib/wcc/scripture/esv.rb', line 21

def initialize(pericope, book_only = false)
  @pericope = pericope
  @book_only = book_only
end

Instance Attribute Details

#pericopeObject (readonly)

Returns the value of attribute pericope.



18
19
20
# File 'lib/wcc/scripture/esv.rb', line 18

def pericope
  @pericope
end

Class Method Details

.parse(ref) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/wcc/scripture/esv.rb', line 26

def self.parse(ref)
  if match = SINGLE_CHAPTER_BOOK_REGEX.match(ref)
    # Pericope will resolve the upper range to the actual when 100 is used
    new(Pericope.parse_one("#{match[0]} 1-100"), true)
  elsif pericope = Pericope.parse_one(ref)
    new(pericope)
  end
end

Instance Method Details

#to_sObject



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/wcc/scripture/esv.rb', line 35

def to_s
  return book_name if @book_only

  result = pericope.to_s(
    verse_range_separator: '',
    chapter_range_separator: ''
  )

  return result unless book_name == 'Psalm' && range_spans_multiple_chapters?

  result.gsub('Psalm', 'Psalms')
end