Class: Stash::Wrapper::DescriptiveNode

Inherits:
XML::Mapping::SingleAttributeNode
  • Object
show all
Defined in:
lib/stash/wrapper/descriptive_node.rb

Overview

Node class for <st:stash_descriptive> elements.

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ DescriptiveNode

See XML::Mapping::SingleAttributeNode#initialize



10
11
12
13
14
# File 'lib/stash/wrapper/descriptive_node.rb', line 10

def initialize(*args)
  path, *myargs = super(*args)
  @path = ::XML::XXPath.new(path)
  myargs # rubocop:disable Lint/Void
end

Instance Method Details

#extract_attr_value(xml) ⇒ Array<REXML::Element>

Extracts the children of this element as an array.

Parameters:

  • xml (REXML::Element)

    this <st:stash_descriptive> element

Returns:

  • (Array<REXML::Element>)

    the child elements



19
20
21
# File 'lib/stash/wrapper/descriptive_node.rb', line 19

def extract_attr_value(xml)
  default_when_xpath_err { @path.first(xml).elements.to_a }
end

#set_attr_value(xml, value) ⇒ Object

Sets the array of elements representetd by this node as the children of the corresponding <st:stash_descriptive> element.

Parameters:

  • xml (REXML::Element)

    this element

  • value (Array<REXML::Element>)

    the child elements



28
29
30
31
32
33
# File 'lib/stash/wrapper/descriptive_node.rb', line 28

def set_attr_value(xml, value)
  parent = @path.first(xml, ensure_created: true)
  value.each do |child|
    parent.elements.add(child)
  end
end