Module: Transform

Includes:
Private
Included in:
ConDuxml
Defined in:
lib/con_duxml/transform.rb

Overview

All public methods can be invoked by a transform element; please hide methods you don’t want users to invoke in Private

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Private

#activate, #add_name_space_prefix, #get_args, #get_method, #get_sources, #normalize_arg, #separate_enumerables

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.



16
17
18
# File 'lib/con_duxml/transform.rb', line 16

def source
  @source
end

Instance Method Details

#content(node) ⇒ Array[String, Element]

Returns array of child nodes of target.

Parameters:

  • node (Element, String)

    XML node including Strings

Returns:

  • (Array[String, Element])

    array of child nodes of target



38
39
40
# File 'lib/con_duxml/transform.rb', line 38

def content(node)
  node.respond_to?(:nodes) ? node.nodes : node
end

#copy(path) ⇒ Element

Returns a deep copy of the target(s).

Parameters:

  • path (String)

    path to node from @source

Returns:

  • (Element)

    a deep copy of the target(s)



51
52
53
54
55
# File 'lib/con_duxml/transform.rb', line 51

def copy(path)
  @source.locate(add_name_space_prefix path).collect do |node|
    node.dclone
  end
end

#element(*args) ⇒ Element

Returns new element to replace old one.

Parameters:

  • *args (*several_variants)

    see Duxml::Element#new; the only difference here is that this method has access to the content source so the arguments can pass in the needed data

Returns:

  • (Element)

    new element to replace old one



45
46
47
# File 'lib/con_duxml/transform.rb', line 45

def element(*args)
  Element.new(*args)
end

#find_source(node) ⇒ Element

Returns XML node that provided content for transformation i.e. source.

Parameters:

  • node (Element)

    XML node from transform output

Returns:

  • (Element)

    XML node that provided content for transformation i.e. source



32
33
34
# File 'lib/con_duxml/transform.rb', line 32

def find_source(node)
  find_xform_event(node).input
end

#find_transform(node) ⇒ Element

Returns XML node that contains instructions for transform used to create given @param node.

Parameters:

  • node (Element)

    XML node from transform output

Returns:

  • (Element)

    XML node that contains instructions for transform used to create given @param node



26
27
28
# File 'lib/con_duxml/transform.rb', line 26

def find_transform(node)
  find_xform_event(node).instructions
end

#find_xform_event(node) ⇒ TransformClass

Returns transform event object from output Doc’s history.

Parameters:

  • node (Element)

    XML node from transform output

Returns:

  • (TransformClass)

    transform event object from output Doc’s history



20
21
22
# File 'lib/con_duxml/transform.rb', line 20

def find_xform_event(node)
  @output.history #TODO find transform whose outputs include given node
end