Module: Duxml::ElementGuts
- Includes:
- Linkable
- Defined in:
- lib/con_duxml/duxml_ext/element.rb
Instance Method Summary collapse
-
#activate ⇒ Array[Element]
Instantiated copy of this Element.
- #merge(pattern = nil, &block) ⇒ Object
- #simple_name ⇒ Object
-
#split(&block) ⇒ Element
A duplicate element of this node initialized with each subset’s nodes.
Methods included from Linkable
Instance Method Details
#activate ⇒ Array[Element]
Returns instantiated copy of this Element.
22 23 24 25 26 27 28 29 30 |
# File 'lib/con_duxml/duxml_ext/element.rb', line 22 def activate if name_space == 'duxml' maudule = ConDuxml.const_get(simple_name.constantize) extend maudule activate else [clone] end end |
#merge(pattern = nil, &block) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/con_duxml/duxml_ext/element.rb', line 38 def merge(pattern=nil, &block) self_clone = self.clone self_clone.nodes = [] chunks = block_given? ? nodes.chunk(&block) : [nil, nodes.dup] chunks.each do |type, chunk| if chunk.size == 1 self_clone.nodes << chunk.first next end merged_args, homogeneous = diff_attrs(chunk, pattern) if homogeneous self_clone.nodes << chunk.first.class.new(chunk.first.name, merged_args) else self_clone << chunk end end # chunks.each do |type, nodes| report :Merge, self_clone self_clone end |
#simple_name ⇒ Object
32 33 34 |
# File 'lib/con_duxml/duxml_ext/element.rb', line 32 def simple_name name.split(':').last end |
#split(&block) ⇒ Element
Returns a duplicate element of this node initialized with each subset’s nodes.
11 12 13 14 15 16 17 18 19 |
# File 'lib/con_duxml/duxml_ext/element.rb', line 11 def split(&block) chunks = nodes.chunk(&block) new_nodes = chunks.collect do |type, nodes| self.class.new(name, nodes) end report :Split, new_nodes new_nodes end |