class PkiExpress::ValidationResults
Attributes
errors[RW]
passed_checks[RW]
warnings[RW]
Public Class Methods
new(model)
click to toggle source
# 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
Public Instance Methods
checks_performed()
click to toggle source
# File lib/pki_express/validation_results.rb, line 60 def checks_performed @errors.length + @warnings.length + @passed_checks.length end
convert_items(items)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# File lib/pki_express/validation_results.rb, line 64 def has_errors @errors && @errors.length > 0 end
has_warnings()
click to toggle source
# File lib/pki_express/validation_results.rb, line 68 def has_warnings @warnings && @warnings.length > 0 end
is_valid()
click to toggle source
# File lib/pki_express/validation_results.rb, line 56 def is_valid not has_errors end
join_items(items, indentation_level=0)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/pki_express/validation_results.rb, line 29 def to_str(indentation_level = 0) to_s(indentation_level) end