Class: Glossarist::ValidationResult
- Inherits:
-
Object
- Object
- Glossarist::ValidationResult
- Defined in:
- lib/glossarist/validation_result.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Instance Method Summary collapse
- #add_error(message) ⇒ Object
- #add_warning(message) ⇒ Object
-
#initialize(errors: [], warnings: []) ⇒ ValidationResult
constructor
A new instance of ValidationResult.
- #merge(other) ⇒ Object
- #to_h ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(errors: [], warnings: []) ⇒ ValidationResult
Returns a new instance of ValidationResult.
7 8 9 10 |
# File 'lib/glossarist/validation_result.rb', line 7 def initialize(errors: [], warnings: []) @errors = errors @warnings = warnings end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
5 6 7 |
# File 'lib/glossarist/validation_result.rb', line 5 def errors @errors end |
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
5 6 7 |
# File 'lib/glossarist/validation_result.rb', line 5 def warnings @warnings end |
Instance Method Details
#add_error(message) ⇒ Object
16 17 18 |
# File 'lib/glossarist/validation_result.rb', line 16 def add_error() @errors << end |
#add_warning(message) ⇒ Object
20 21 22 |
# File 'lib/glossarist/validation_result.rb', line 20 def add_warning() @warnings << end |
#merge(other) ⇒ Object
24 25 26 27 28 |
# File 'lib/glossarist/validation_result.rb', line 24 def merge(other) other.errors.each { |e| add_error(e) } other.warnings.each { |w| add_warning(w) } self end |
#to_h ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/glossarist/validation_result.rb', line 30 def to_h { "valid" => valid?, "errors" => errors, "warnings" => warnings, } end |
#valid? ⇒ Boolean
12 13 14 |
# File 'lib/glossarist/validation_result.rb', line 12 def valid? @errors.empty? end |