Class: BibleBot::ReferenceMatch
- Inherits:
-
Object
- Object
- BibleBot::ReferenceMatch
- Defined in:
- lib/bible_bot/reference_match.rb
Overview
You shouldn’t need to use this class directly. For the majority of use cases, just use BibleBot::Reference.parse.
This class contains all the logic for mapping the different parts of a scripture Match into an actual Reference. It wraps the Match returned from the regular expression defined in Bible.scripture_re.
A scripture reference can take many forms, but the least abbreviated form is:
Genesis 1:1 - Genesis 1:2
Internally, this class represents this form using the following variables:
b1 c1:v1 - b2 c2:v2
See Readme for list of supported abbreviation rules.
Advanced Use Cases
This is a low level class used internally by BibleBot::Reference.parse. There are however some advanced use cases which you might want to use it for. For example, if you want to know where in the parsed String certain matches occur.
For this there are a few convenience attributes:
Instance Attribute Summary collapse
-
#length ⇒ Integer
readonly
The length of the match in the text string.
-
#match ⇒ Match
readonly
The Match instance returned from the Regexp.
-
#offset ⇒ Integer
readonly
The starting position of the match in the text string.
Class Method Summary collapse
-
.scan(text) ⇒ Array<ReferenceMatch>
Converts a string into an array of ReferenceMatches.
Instance Method Summary collapse
-
#reference ⇒ Reference
Note: Reference is not yet validated.
Instance Attribute Details
#length ⇒ Integer (readonly)
Returns The length of the match in the text string.
39 40 41 |
# File 'lib/bible_bot/reference_match.rb', line 39 def length @length end |
#match ⇒ Match (readonly)
Returns The Match instance returned from the Regexp.
38 39 40 |
# File 'lib/bible_bot/reference_match.rb', line 38 def match @match end |
#offset ⇒ Integer (readonly)
Returns The starting position of the match in the text string.
40 41 42 |
# File 'lib/bible_bot/reference_match.rb', line 40 def offset @offset end |
Class Method Details
.scan(text) ⇒ Array<ReferenceMatch>
Converts a string into an array of ReferenceMatches. Note: Does not validate References.
47 48 49 50 51 52 |
# File 'lib/bible_bot/reference_match.rb', line 47 def self.scan(text) scripture_reg = Bible.scripture_re Array.new.tap do |matches| text.scan(scripture_reg){ matches << self.new($~, $~.offset(0)[0]) } end end |
Instance Method Details
#reference ⇒ Reference
Returns Note: Reference is not yet validated.
55 56 57 58 59 60 |
# File 'lib/bible_bot/reference_match.rb', line 55 def reference @reference ||= Reference.new( start_verse: Verse.new(book: start_book, chapter_number: start_chapter.to_i, verse_number: start_verse.to_i), end_verse: Verse.new(book: end_book, chapter_number: end_chapter.to_i, verse_number: end_verse.to_i), ) end |