Class: ValidatesXmlOf::Validator

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

Instance Method Summary collapse

Constructor Details

#initialize(xml, options = {}) ⇒ Validator

Returns a new instance of Validator.



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

def initialize(xml, options = {})
  self.xml = xml
  self.options = options
end

Instance Method Details

#validateObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/validates_xml_of/validator.rb', line 8

def validate
  message = nil

  if xml.nil? || xml.empty? || !xml.is_a?(String)
    if options[:schema]
      message = merged_options[:schema_message]
    else
      message = merged_options[:message]
    end
  end

  if !is_a_valid_xml?(xml)
    message = merged_options[:message]
  end

  return message unless message.nil?

  if options[:schema]
    schema = lookup_schema_file(options[:schema])

    return merged_options[:schema_message] if schema.nil?

    if !schema.nil? && !is_a_valid_xml_based_on_schema?(xml, schema)
      message = merged_options[:schema_message]
    end
  end

  return message
end