Class: Cuporter::TagListNode

Inherits:
Node
  • Object
show all
Defined in:
lib/cuporter/tag_list_node.rb

Overview

a node with a list of tags that can be applied to all children

Direct Known Subclasses

ExampleSetNode

Instance Attribute Summary collapse

Attributes inherited from Node

#children, #file, #name, #number, #numerable

Instance Method Summary collapse

Methods inherited from Node

#<=>, #add_child, #eql?, #find, #find_by_name, #find_or_create_child, #has_children?, #name_without_title, #names, #number_all_descendants, #numerable?, #sort!, #sort_all_descendants!, #total

Constructor Details

#initialize(name, tags) ⇒ TagListNode

Returns a new instance of TagListNode.



8
9
10
11
# File 'lib/cuporter/tag_list_node.rb', line 8

def initialize(name, tags)
  super(name)
  @tags = tags
end

Instance Attribute Details

#tagsObject (readonly)

Returns the value of attribute tags.



6
7
8
# File 'lib/cuporter/tag_list_node.rb', line 6

def tags
  @tags
end

Instance Method Details

#add_to_tag_nodes(node) ⇒ Object



17
18
19
20
21
22
# File 'lib/cuporter/tag_list_node.rb', line 17

def add_to_tag_nodes(node)
  (tags | node.tags).each do |tag|
    tag_node = find_or_create_child(tag)
    tag_node.add_child(node)
  end
end

#has_tags?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/cuporter/tag_list_node.rb', line 13

def has_tags?
  @tags.size > 0
end

#merge(other) ⇒ Object

Have my children adopt the other node’s grandchildren.

Copy children of other node’s top-level, direct descendants to this node’s direct descendants of the same name.



28
29
30
31
32
33
34
35
36
37
# File 'lib/cuporter/tag_list_node.rb', line 28

def merge(other)
  other.children.each do |other_child|
    direct_child               = find_or_create_child(other_child.name)
    new_grandchild             = Node.new(other.name)
    new_grandchild.children    = other_child.children
    new_grandchild.file        = other.file

    direct_child.add_child(new_grandchild)
  end
end