Module: BibleReferenceParser::TracksErrors

Included in:
BookReference, ChapterReference, ReferenceCollection, VerseReference
Defined in:
lib/bible_reference_parser/reference/behavior/tracks_errors.rb

Overview

This module encapsulates shared behavior for classes that keep track of parsing errors. For example, a BookReference may encounter a parsing error due to a book that doesn’t exist. A ChapterReference may have a parsing error because the chapter number isn’t valid for the book it is referencing.

Instance Method Summary collapse

Instance Method Details

#add_error(message) ⇒ Object

Add an error message.



17
18
19
# File 'lib/bible_reference_parser/reference/behavior/tracks_errors.rb', line 17

def add_error(message)
  @errors << message
end

#clear_errorsObject

Erase all error messages.



22
23
24
# File 'lib/bible_reference_parser/reference/behavior/tracks_errors.rb', line 22

def clear_errors
  @errors = []
end

#errors(include_child_errors = true) ⇒ Object

Get the list of error messages. This will include any errors in child references if include_child_errors is true (by default it’s true).



28
29
30
31
32
33
34
# File 'lib/bible_reference_parser/reference/behavior/tracks_errors.rb', line 28

def errors(include_child_errors = true)
  if(include_child_errors && respond_to?("children") && children)
    return @errors + children.errors(true)
  end
  
  @errors
end

#has_errors?Boolean

Whether any errors occured when parsing.

Returns:

  • (Boolean)


37
38
39
# File 'lib/bible_reference_parser/reference/behavior/tracks_errors.rb', line 37

def has_errors?
  !errors.empty?
end

#initialize(*args, &block) ⇒ Object



9
10
11
12
13
14
# File 'lib/bible_reference_parser/reference/behavior/tracks_errors.rb', line 9

def initialize(*args, &block) 
  super
   
  # A collection of error messages.                         
  @errors = []
end

#no_errors?Boolean

Convienence method for the reverse of “has_errors?”

Returns:

  • (Boolean)


42
43
44
# File 'lib/bible_reference_parser/reference/behavior/tracks_errors.rb', line 42

def no_errors?
  errors.empty?
end