class Hashematics::Visitor
A Visitor
is a Record
found in the context of a Group
. When traversing the object graph (group tree), it will provide these Visitor
objects instead of Record
objects that allows you to view the Record
in the context of the graph, while a Record
is more of just the raw payload provided by the initial flat data set.
Attributes
group[R]
record[R]
Public Class Methods
new(group:, record:)
click to toggle source
# File lib/hashematics/visitor.rb, line 22 def initialize(group:, record:) @group = group @record = record freeze end
Public Instance Methods
data(include_children = false)
click to toggle source
# File lib/hashematics/visitor.rb, line 29 def data(include_children = false) child_hash = include_children ? make_child_hash : {} type.convert(record.data, child_hash) end
visit(name)
click to toggle source
# File lib/hashematics/visitor.rb, line 35 def visit(name) group.visit_children(name, record) end
Private Instance Methods
make_child_hash()
click to toggle source
# File lib/hashematics/visitor.rb, line 41 def make_child_hash children.map do |name| [ name, visit(name).map { |v| v.data(true) } ] end.to_h end