Class: Hashematics::Visitor

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#groupObject (readonly)

Returns the value of attribute group.



20
21
22
# File 'lib/hashematics/visitor.rb', line 20

def group
  @group
end

#recordObject (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