Class: Cuporter::TagListNode
Overview
a node with a list of tags that can be applied to all children
Direct Known Subclasses
Instance Attribute Summary collapse
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Attributes inherited from Node
#children, #file, #name, #number, #numerable
Instance Method Summary collapse
- #add_to_tag_nodes(node) ⇒ Object
- #has_tags? ⇒ Boolean
-
#initialize(name, tags) ⇒ TagListNode
constructor
A new instance of TagListNode.
-
#merge(other) ⇒ Object
Have my children adopt the other node’s grandchildren.
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, ) super(name) @tags = end |
Instance Attribute Details
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
6 7 8 |
# File 'lib/cuporter/tag_list_node.rb', line 6 def @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) ( | node.).each do |tag| tag_node = find_or_create_child(tag) tag_node.add_child(node) end end |
#has_tags? ⇒ Boolean
13 14 15 |
# File 'lib/cuporter/tag_list_node.rb', line 13 def @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 |