Class: Bioinform::ValidationResult
- Inherits:
-
Object
- Object
- Bioinform::ValidationResult
- Defined in:
- lib/bioinform/validator.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Class Method Summary collapse
Instance Method Summary collapse
-
#+(other) ⇒ Object
errors from both operands.
- #==(other) ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(errors: [], warnings: []) ⇒ ValidationResult
constructor
A new instance of ValidationResult.
- #to_s ⇒ Object
- #valid? ⇒ Boolean
- #with_errors(additional_errors) ⇒ Object
- #with_warnings(additional_warnings) ⇒ Object
Constructor Details
#initialize(errors: [], warnings: []) ⇒ ValidationResult
Returns a new instance of ValidationResult.
4 5 6 7 |
# File 'lib/bioinform/validator.rb', line 4 def initialize(errors: [], warnings: []) @errors = errors.freeze @warnings = warnings.freeze end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
3 4 5 |
# File 'lib/bioinform/validator.rb', line 3 def errors @errors end |
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
3 4 5 |
# File 'lib/bioinform/validator.rb', line 3 def warnings @warnings end |
Class Method Details
.all_ok ⇒ Object
9 10 11 |
# File 'lib/bioinform/validator.rb', line 9 def self.all_ok self.new(errors: [], warnings: []) end |
Instance Method Details
#+(other) ⇒ Object
errors from both operands
40 41 42 |
# File 'lib/bioinform/validator.rb', line 40 def +(other) ValidationResult.new(errors: errors + other.errors, warnings: warnings + other.warnings) end |
#==(other) ⇒ Object
50 51 52 |
# File 'lib/bioinform/validator.rb', line 50 def ==(other) other.is_a?(ValidationResult) && (errors == other.errors) && (warnings == other.warnings) end |
#eql?(other) ⇒ Boolean
47 48 49 |
# File 'lib/bioinform/validator.rb', line 47 def eql?(other) (other.class == self.class) && (errors == other.errors) && (warnings == other.warnings) end |
#hash ⇒ Object
44 45 46 |
# File 'lib/bioinform/validator.rb', line 44 def hash [@errors, @warnings].hash end |
#to_s ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/bioinform/validator.rb', line 17 def to_s msg = "" if errors && !errors.empty? msg += "Errors:\n" + errors.join("\n") + "\n" end if warnings && !warnings.empty? msg += "Warnings:\n" + warnings.join("\n") end msg.empty? ? "{No errors, no warnings}" : "{#{msg}}" end |
#valid? ⇒ Boolean
13 14 15 |
# File 'lib/bioinform/validator.rb', line 13 def valid? errors.empty? end |
#with_errors(additional_errors) ⇒ Object
31 32 33 |
# File 'lib/bioinform/validator.rb', line 31 def with_errors(additional_errors) ValidationResult.new(errors: errors + additional_errors, warnings: warnings) end |
#with_warnings(additional_warnings) ⇒ Object
35 36 37 |
# File 'lib/bioinform/validator.rb', line 35 def with_warnings(additional_warnings) ValidationResult.new(errors: errors, warnings: warnings + additional_warnings) end |