Class: Bioinform::ValidationResult

Inherits:
Object
  • Object
show all
Defined in:
lib/bioinform/validator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#errorsObject (readonly)

Returns the value of attribute errors.



3
4
5
# File 'lib/bioinform/validator.rb', line 3

def errors
  @errors
end

#warningsObject (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_okObject



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

Returns:

  • (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

#hashObject



44
45
46
# File 'lib/bioinform/validator.rb', line 44

def hash
  [@errors, @warnings].hash
end

#to_sObject



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

Returns:

  • (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