Module: ConDuxml::Instance

Included in:
Link
Defined in:
lib/con_duxml/instance.rb

Overview

Instances are copies of another XML element with a distinct set of parameter values like Objects in relation to a Class

Instance Method Summary collapse

Instance Method Details

#activateArray[Element, String]

Returns array (or NodeSet) of either shallow clone of child nodes or referenced nodes @see #ref=.

Returns:

  • (Array[Element, String])

    array (or NodeSet) of either shallow clone of child nodes or referenced nodes @see #ref=



28
29
30
# File 'lib/con_duxml/instance.rb', line 28

def activate
  [resolve_ref || nodes].flatten.clone
end

#ref=(target) ⇒ Element

Returns self.

Parameters:

  • target (String)

    path to target node or file

Returns:

  • (Element)

    self

Raises:

  • (Exception)


10
11
12
13
# File 'lib/con_duxml/instance.rb', line 10

def ref=(target)
  raise Exception unless doc.locate(target) or File.exists?(target)
  self[:ref] = target
end

#resolve_ref(attr = 'ref') ⇒ Element

Returns either root node of referenced Doc or referenced node.

Returns:

  • (Element)

    either root node of referenced Doc or referenced node



16
17
18
19
20
21
22
23
24
25
# File 'lib/con_duxml/instance.rb', line 16

def resolve_ref(attr='ref')
  source = if self[:file]
             path = File.expand_path(File.dirname(doc.path) + '/' + self[:file])
             sax path
           else
             doc
           end
  return source.locate(self[attr]).first if self[attr]
  source.root if self[:file]
end