Class: Coradoc::Reference::Presentation::CustomHierarchy::VisitorById

Inherits:
Object
  • Object
show all
Defined in:
lib/coradoc/reference/presentation/custom_hierarchy.rb

Overview

Single-purpose visitor: walks a CoreModel tree looking for one node by id. Cleaner than a recursive method on the presentation class itself.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target_id) ⇒ VisitorById

Returns a new instance of VisitorById.



74
75
76
77
# File 'lib/coradoc/reference/presentation/custom_hierarchy.rb', line 74

def initialize(target_id)
  @target_id = target_id
  @found = nil
end

Instance Attribute Details

#foundObject (readonly)

Returns the value of attribute found.



72
73
74
# File 'lib/coradoc/reference/presentation/custom_hierarchy.rb', line 72

def found
  @found
end

Instance Method Details

#visit(node) ⇒ Object



79
80
81
82
83
84
85
86
87
# File 'lib/coradoc/reference/presentation/custom_hierarchy.rb', line 79

def visit(node)
  return @found if @found
  return unless node.is_a?(Coradoc::CoreModel::Base)

  @found = node if node.id == @target_id
  return if @found

  visit_children(node)
end