Class: RestPki::ValidationResults
- Inherits:
-
Object
- Object
- RestPki::ValidationResults
- Defined in:
- lib/rest_pki/validation_results.rb
Instance Method Summary collapse
- #__to_string ⇒ Object
- #get_checks_performed ⇒ Object
- #get_summary(indentation_level = 0) ⇒ Object
- #has_errors ⇒ Object
- #has_passed_checks ⇒ Object
- #has_warnings ⇒ Object
-
#initialize(model) ⇒ ValidationResults
constructor
A new instance of ValidationResults.
- #is_valid ⇒ Object
- #to_string(indentation_level) ⇒ Object
Constructor Details
#initialize(model) ⇒ ValidationResults
Returns a new instance of ValidationResults.
5 6 7 8 9 |
# File 'lib/rest_pki/validation_results.rb', line 5 def initialize(model) @errors = convert_items(model['errors']) @warnings = convert_items(model['warnings']) @passed_checks = convert_items(model['passedChecks']) end |
Instance Method Details
#__to_string ⇒ Object
31 32 33 |
# File 'lib/rest_pki/validation_results.rb', line 31 def __to_string to_string(0) end |
#get_checks_performed ⇒ Object
15 16 17 |
# File 'lib/rest_pki/validation_results.rb', line 15 def get_checks_performed @errors.to_a.length + @warnings.to_a.length + @passed_checks.to_a.length end |
#get_summary(indentation_level = 0) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/rest_pki/validation_results.rb', line 55 def get_summary(indentation_level=0) tab = '' (1..indentation_level).each do; tab += '\t'; end text = "#{tab}Validation results: " if get_checks_performed == 0 text += 'no checks performed' else text += "#{get_checks_performed} checks performed" if has_errors text += ", #{@errors.to_a.length} errors" end if has_warnings text += ", #{@warnings.to_a.length} warnings" end if has_passed_checks if !has_errors && !has_warnings text += ', all passed' else text += ", #{@passed_checks.to_a.length} passed" end end end text end |
#has_errors ⇒ Object
19 20 21 |
# File 'lib/rest_pki/validation_results.rb', line 19 def has_errors !is_valid end |
#has_passed_checks ⇒ Object
27 28 29 |
# File 'lib/rest_pki/validation_results.rb', line 27 def has_passed_checks @passed_checks.to_a.any? end |
#has_warnings ⇒ Object
23 24 25 |
# File 'lib/rest_pki/validation_results.rb', line 23 def has_warnings @warnings.to_a.any? end |
#is_valid ⇒ Object
11 12 13 |
# File 'lib/rest_pki/validation_results.rb', line 11 def is_valid @errors.to_a.empty? end |
#to_string(indentation_level) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rest_pki/validation_results.rb', line 35 def to_string(indentation_level) tab = '' (1..indentation_level).each do; tab += '\t'; end text = '' text += get_summary(indentation_level) if has_errors text += "\n#{tab}Errors:\n" text += join_items(@errors, indentation_level) end if has_warnings text += "\n#{tab}Warnings:\n" text += join_items(@warnings, indentation_level) end if has_passed_checks text += "\n#{tab}Passed checks:\n" text += join_items(@passed_checks, indentation_level) end text end |