Class: PkiExpress::ValidationResults
- Inherits:
-
Object
- Object
- PkiExpress::ValidationResults
- Defined in:
- lib/pki_express/validation_results.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#passed_checks ⇒ Object
Returns the value of attribute passed_checks.
-
#warnings ⇒ Object
Returns the value of attribute warnings.
Instance Method Summary collapse
- #checks_performed ⇒ Object
- #convert_items(items) ⇒ Object
- #get_summary(indentation_level = 0) ⇒ Object
- #has_errors ⇒ Object
- #has_warnings ⇒ Object
-
#initialize(model) ⇒ ValidationResults
constructor
A new instance of ValidationResults.
- #is_valid ⇒ Object
- #join_items(items, indentation_level = 0) ⇒ Object
- #to_s(indentation_level = 0) ⇒ Object
- #to_str(indentation_level = 0) ⇒ Object
Constructor Details
#initialize(model) ⇒ ValidationResults
Returns a new instance of ValidationResults.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/pki_express/validation_results.rb', line 6 def initialize(model) @errors = [] @warnings = [] @passed_checks = [] if model errors = model.fetch(:errors) if errors @errors = convert_items(errors) end warnings = model.fetch(:warnings) if warnings @warnings = convert_items(warnings) end passed_checks = model.fetch(:passedChecks) if passed_checks @passed_checks = convert_items(passed_checks) end end end |
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
4 5 6 |
# File 'lib/pki_express/validation_results.rb', line 4 def errors @errors end |
#passed_checks ⇒ Object
Returns the value of attribute passed_checks.
4 5 6 |
# File 'lib/pki_express/validation_results.rb', line 4 def passed_checks @passed_checks end |
#warnings ⇒ Object
Returns the value of attribute warnings.
4 5 6 |
# File 'lib/pki_express/validation_results.rb', line 4 def warnings @warnings end |
Instance Method Details
#checks_performed ⇒ Object
60 61 62 |
# File 'lib/pki_express/validation_results.rb', line 60 def checks_performed @errors.length + @warnings.length + @passed_checks.length end |
#convert_items(items) ⇒ Object
98 99 100 |
# File 'lib/pki_express/validation_results.rb', line 98 def convert_items(items) items.map { |i| ValidationItem.new(i) } end |
#get_summary(indentation_level = 0) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/pki_express/validation_results.rb', line 72 def get_summary(indentation_level=0) item_indent = "\t" * indentation_level text = "#{item_indent}Validation Results: " if checks_performed == 0 text += 'no checks performed' else text += "#{checks_performed} checks performed" if has_errors text += ", #{@errors.length} errors" end if has_warnings text += ", #{@warnings.length} warnings" end if not @passed_checks.nil? and @passed_checks.length if not has_errors and not has_warnings text += ', all passed' else text += ", #{@passed_checks.length} passed" end end end text end |
#has_errors ⇒ Object
64 65 66 |
# File 'lib/pki_express/validation_results.rb', line 64 def has_errors @errors && @errors.length > 0 end |
#has_warnings ⇒ Object
68 69 70 |
# File 'lib/pki_express/validation_results.rb', line 68 def has_warnings @warnings && @warnings.length > 0 end |
#is_valid ⇒ Object
56 57 58 |
# File 'lib/pki_express/validation_results.rb', line 56 def is_valid not has_errors end |
#join_items(items, indentation_level = 0) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/pki_express/validation_results.rb', line 102 def join_items(items, indentation_level=0) text = '' is_first = true item_indent = "\t" * indentation_level items.each do |i| if is_first is_first = false else text += "\n" end text += item_indent + '- ' text += i.to_s(indentation_level) end text end |
#to_s(indentation_level = 0) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/pki_express/validation_results.rb', line 33 def to_s(indentation_level = 0) item_indent = "\t" * indentation_level text = '' text += get_summary(indentation_level) if has_errors text += "\n#{item_indent}Errors:\n" text += join_items(@errors, indentation_level) end if has_warnings text += "\n#{item_indent}Warnings:\n" text += join_items(@warnings, indentation_level) end if not @passed_checks.nil? and @passed_checks.length > 0 text += "\n#{item_indent}Passed Checks:\n" text += join_items(@passed_checks, indentation_level) end text end |
#to_str(indentation_level = 0) ⇒ Object
29 30 31 |
# File 'lib/pki_express/validation_results.rb', line 29 def to_str(indentation_level = 0) to_s(indentation_level) end |