class Hashematics::Group
A group is a node in a tree structure connected to other groups through the children attribute. A group essentially represents an object within the object graph and its:
Attributes
category[R]
child_dictionary[R]
name[R]
type[R]
Public Class Methods
new(category:, children:, name:, type:)
click to toggle source
# File lib/hashematics/group.rb, line 18 def initialize(category:, children:, name:, type:) @category = category @child_dictionary = Dictionary.new.add(children, &:name) @name = name @type = type freeze end
Public Instance Methods
add(record)
click to toggle source
# File lib/hashematics/group.rb, line 27 def add(record) category.add(record) child_dictionary.each { |c| c.add(record) } self end
children()
click to toggle source
# File lib/hashematics/group.rb, line 35 def children child_dictionary.map(&:name) end
visit(parent_record = nil)
click to toggle source
# File lib/hashematics/group.rb, line 39 def visit(parent_record = nil) category.records(parent_record).map do |record| Visitor.new(group: self, record: record) end end
visit_children(name, parent_record = nil)
click to toggle source
# File lib/hashematics/group.rb, line 45 def visit_children(name, parent_record = nil) child_group(name)&.visit(parent_record) || [] end
Private Instance Methods
child_group(group_name)
click to toggle source
# File lib/hashematics/group.rb, line 53 def child_group(group_name) child_dictionary.get(group_name) end