Class: MatchPoint::XmlInstance

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

Constant Summary collapse

SPEC_NODE =
"MatchPointSpec"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_hash(template, data) ⇒ Object



12
13
14
15
16
# File 'lib/match_point/xml_instance.rb', line 12

def self.from_hash template, data
  instance = self.new template
  instance.assign_values data
  instance
end

.from_xml(template, xml, error_node) ⇒ Object



6
7
8
9
10
# File 'lib/match_point/xml_instance.rb', line 6

def self.from_xml template, xml, error_node
  instance = self.new template, xml
  instance.error_node = error_node
  instance
end

Instance Method Details

#assign_values(data) ⇒ Object



47
48
49
50
51
# File 'lib/match_point/xml_instance.rb', line 47

def assign_values data
  data.each do |key, value|
    assign_value value, node_path(key)
  end
end

#at_xpath(a_path) ⇒ Object



43
44
45
# File 'lib/match_point/xml_instance.rb', line 43

def at_xpath a_path
  document.at_xpath a_path
end

#documentObject



38
39
40
41
# File 'lib/match_point/xml_instance.rb', line 38

def document
  xml = @xml.document.clone
  remove_unassigned_values_from xml
end

#error_node=(error_node) ⇒ Object



18
19
20
# File 'lib/match_point/xml_instance.rb', line 18

def error_node= error_node
  @error_node = error_node
end

#inject_node(new_node, injection_path) ⇒ Object



57
58
59
60
61
# File 'lib/match_point/xml_instance.rb', line 57

def inject_node(new_node, injection_path)
  self_node = @xml.at_xpath(injection_path)
  self_node.add_child(new_node)

end

#operation_nameObject



30
31
32
# File 'lib/match_point/xml_instance.rb', line 30

def operation_name
  @operation_name
end

#operation_name=(a_name) ⇒ Object



34
35
36
# File 'lib/match_point/xml_instance.rb', line 34

def operation_name= a_name
  @operation_name = a_name
end

#success?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/match_point/xml_instance.rb', line 53

def success?
  !@xml.at_xpath(@error_node[:path]).has_attribute?(@error_node[:attribute])
end

#to_sObject



26
27
28
# File 'lib/match_point/xml_instance.rb', line 26

def to_s
  @xml.to_s
end

#to_xmlObject



22
23
24
# File 'lib/match_point/xml_instance.rb', line 22

def to_xml
  @xml.to_xml
end