13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/opinionated-xml/ox_property_values_helper.rb', line 13
def property_values_append(opts={})
parent_select = opts[:parent_select]
parent_index = opts[:parent_index]
template = opts[:template]
new_values = opts[:values]
unless template.instance_of?(String)
template_args = Array(template)
if template_args.last.kind_of?(Hash)
template_opts = template_args.delete_at(template_args.length - 1)
else
template_opts = {}
end
template = self.class.builder_template( template_args, template_opts )
end
new_values = Array(new_values)
parent_select = Array(parent_select)
parent_nodeset = lookup(parent_select[0], parent_select[1])
if parent_index.kind_of?(Integer)
parent_node = parent_nodeset[parent_index]
elsif parent_index.kind_of?(Symbol) && parent_nodeset.respond_to?(parent_index)
parent_node = parent_nodeset.send(parent_index)
end
if parent_node.nil?
raise OX::ParentNodeNotFoundError, "Failed to find a parent node to insert values into based on :parent_select #{parent_select.inspect} with :parent_index #{parent_index.inspect}"
end
builder = Nokogiri::XML::Builder.with(parent_node) do |xml|
new_values.each do |builder_new_value|
builder_arg = eval('"'+ template + '"') eval(builder_arg)
end
end
return parent_node
end
|