Class: Hashematics::Visitor
- Inherits:
-
Object
- Object
- Hashematics::Visitor
- Extended by:
- Forwardable
- Defined in:
- lib/hashematics/visitor.rb
Overview
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.
Instance Attribute Summary collapse
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
Instance Method Summary collapse
- #data(include_children = false) ⇒ Object
-
#initialize(group:, record:) ⇒ Visitor
constructor
A new instance of Visitor.
- #visit(name) ⇒ Object
Constructor Details
#initialize(group:, record:) ⇒ Visitor
Returns a new instance of Visitor.
22 23 24 25 26 27 |
# File 'lib/hashematics/visitor.rb', line 22 def initialize(group:, record:) @group = group @record = record freeze end |
Instance Attribute Details
#group ⇒ Object (readonly)
Returns the value of attribute group.
20 21 22 |
# File 'lib/hashematics/visitor.rb', line 20 def group @group end |
#record ⇒ Object (readonly)
Returns the value of attribute record.
20 21 22 |
# File 'lib/hashematics/visitor.rb', line 20 def record @record end |
Instance Method Details
#data(include_children = false) ⇒ Object
29 30 31 32 33 |
# 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) ⇒ Object
35 36 37 |
# File 'lib/hashematics/visitor.rb', line 35 def visit(name) group.visit_children(name, record) end |