Module: OM::XML::PropertyValueOperators
- Defined in:
- lib/om/xml/property_value_operators.rb
Instance Method Summary collapse
-
#property_value_delete(opts = {}) ⇒ Object
def property_value_set(property_ref, query_opts, node_index, new_value) end.
- #property_value_update(opts = {}) ⇒ Object
- #property_values(lookup_args) ⇒ Object
- #property_values_append(opts = {}) ⇒ Object
Instance Method Details
#property_value_delete(opts = {}) ⇒ Object
def property_value_set(property_ref, query_opts, node_index, new_value) end
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/om/xml/property_value_operators.rb', line 71 def property_value_delete(opts={}) parent_select = Array( opts[:parent_select] ) parent_index = opts[:parent_index] child_index = opts[:child_index] xpath_select = opts[:select] if !xpath_select.nil? node = lookup(xpath_select, nil).first else parent_nodeset = lookup(parent_select, parent_select) # parent_nodeset = lookup(parent_select[0]) if parent_index.nil? node = node_from_set(parent_nodeset, child_index) else parent = node_from_set(parent_nodeset, parent_index) # this next line is a hack around the fact that element_children() sometimes doesn't work. node = node_from_set(parent.xpath("*"), child_index) end end node.remove end |
#property_value_update(opts = {}) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/om/xml/property_value_operators.rb', line 50 def property_value_update(opts={}) parent_select = Array( opts[:parent_select] ) child_index = opts[:child_index] template = opts[:template] new_value = opts[:value] xpath_select = opts[:select] if !xpath_select.nil? node = lookup(xpath_select, nil).first else parent_nodeset = lookup(parent_select[0], parent_select[1]) node = node_from_set(parent_nodeset, child_index) end node.content = new_value end |
#property_values(lookup_args) ⇒ Object
7 8 9 10 11 |
# File 'lib/om/xml/property_value_operators.rb', line 7 def property_values(lookup_args) result = [] lookup(lookup_args).each {|node| result << node.text } return result end |
#property_values_append(opts = {}) ⇒ Object
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 |
# File 'lib/om/xml/property_value_operators.rb', line 13 def property_values_append(opts={}) parent_select = Array( opts[:parent_select] ) child_index = opts[:child_index] template = opts[:template] new_values = Array( opts[:values] ) # If template is a string, use it as the template, otherwise use it as arguments to builder_template 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 parent_nodeset = lookup(parent_select[0], parent_select[1]) parent_node = node_from_set(parent_nodeset, child_index) 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 :child_index #{child_index.inspect}" end builder = Nokogiri::XML::Builder.with(parent_node) do |xml| new_values.each do |builder_new_value| builder_arg = eval('"'+ template + '"') # this inserts builder_new_value into the builder template eval(builder_arg) end end # Nokogiri::XML::Node.new(builder.to_xml, foo) return parent_node end |