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
- #filter_child(node, node_tags) ⇒ Object
- #find_or_create_child(name) ⇒ Object
- #has_tags? ⇒ Boolean
-
#initialize(name, tags, filter = {}) ⇒ TagListNode
constructor
A new instance of TagListNode.
-
#merge_tag_nodes(other) ⇒ Object
Have my children adopt the other node’s grandchildren.
Methods inherited from Node
#<=>, #add_child, #eql?, #find, #find_by_name, #has_children?, #name_without_title, #names, #number_all_descendants, #numerable?, #sort!, #sort_all_descendants!, #total
Constructor Details
#initialize(name, tags, filter = {}) ⇒ TagListNode
Returns a new instance of TagListNode.
8 9 10 11 12 |
# File 'lib/cuporter/tag_list_node.rb', line 8 def initialize(name, , filter = {}) super(name) @tags = @filter = filter 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
22 23 24 25 26 27 |
# File 'lib/cuporter/tag_list_node.rb', line 22 def add_to_tag_nodes(node) ( | node.).each do |tag| tag_node = find_or_create_child(tag) tag_node.add_child(node) end end |
#filter_child(node, node_tags) ⇒ Object
18 19 20 |
# File 'lib/cuporter/tag_list_node.rb', line 18 def filter_child(node, ) add_child(node) if @filter.pass?( | ) end |
#find_or_create_child(name) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/cuporter/tag_list_node.rb', line 44 def find_or_create_child(name) child_node = self[name] unless child_node children << Node.new(name) child_node = children.last end child_node end |
#has_tags? ⇒ Boolean
14 15 16 |
# File 'lib/cuporter/tag_list_node.rb', line 14 def @tags.size > 0 end |
#merge_tag_nodes(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.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/cuporter/tag_list_node.rb', line 33 def merge_tag_nodes(other) other.children.each do |other_tag_node| tag_node = find_or_create_child(other_tag_node.name) new_grandchild = Node.new(other.name) new_grandchild.children = other_tag_node.children new_grandchild.file = other.file tag_node.add_child(new_grandchild) end end |