Module: Transform

Includes:
Observable, 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

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.



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

def source
  @source
end

Instance Method Details

#content(path) ⇒ String

Returns content of target node.

Parameters:

  • path (String)

    path to node from @source e.g. ‘child/grandchild’; target is expected to return ONE child containing TEXT only

Returns:

  • (String)

    content of target node



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

def content(path)
  @source.locate(add_name_space_prefix path).first.text
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



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

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



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

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



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

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

end