Class: Validation::Validator

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

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Validator) initialize(doc_type)



54
55
56
57
# File 'lib/validation.rb', line 54

def initialize(doc_type)
  @validators = []
  @doc_type= doc_type
end

Instance Attribute Details

- (Object) validators

Returns the value of attribute validators



50
51
52
# File 'lib/validation.rb', line 50

def validators
  @validators
end

Instance Method Details

- (Object) <<(validator)



79
80
81
82
83
# File 'lib/validation.rb', line 79

def << (validator)

     raise InvalidValidatorException if !validator.kind_of? Validation::BaseValidator
     validators << validator
end

- (Boolean) contains?(validator)



85
86
87
# File 'lib/validation.rb', line 85

def contains?(validator)
  validators.include?(validator)
end

- (Boolean) contains_kind_of?(validator)



89
90
91
# File 'lib/validation.rb', line 89

def contains_kind_of?(validator)
  validators.any? {|v| v.kind_of?(validator)}
end

- (Object) validate(patient_data, document, options = {})



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/validation.rb', line 59

def validate(patient_data, document, options = {})
  logger = options[:logger]
  errors = []
  # see if we have been given a ClinicalDocument, if so, get the xml
  xml_document = document.respond_to?(:as_xml_document) ? document.as_xml_document : document
  # and get the public path to the file if available
  xml_file_path = document.public_filename if document.respond_to?(:public_filename)
  validators.each do |validator|
    validator.logger = logger if logger
    case validator
      when FileValidator
        errors.concat(validator.validate(patient_data, xml_file_path))
      else
        errors.concat(validator.validate(patient_data, xml_document))
    end
  end

  errors
end