Class: Coradoc::Visitor::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/coradoc/visitor.rb

Overview

Base class for document visitors.

Provides default traversal behavior for all CoreModel types. Override specific visit_* methods to customize behavior.

Direct Known Subclasses

Collector, Finder, Transformer

Instance Method Summary collapse

Instance Method Details

#visit(element) ⇒ void

This method returns an undefined value.

Visit a document element (dispatch method)

Parameters:



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/coradoc/visitor.rb', line 50

def visit(element)
  return if element.nil?

  method_name = DISPATCH_TABLE[element.class]
  if method_name
    send(method_name, element)
  elsif element.is_a?(Array)
    visit_array(element)
  else
    visit_unknown(element)
  end
end

#visit_abbreviation(element) ⇒ Object

Visit an abbreviation



129
130
131
# File 'lib/coradoc/visitor.rb', line 129

def visit_abbreviation(element)
  # Abbreviation is typically a leaf node
end

#visit_annotation_block(block) ⇒ Object

Visit an annotation block (admonition)



114
115
116
# File 'lib/coradoc/visitor.rb', line 114

def visit_annotation_block(block)
  visit_children(block.children)
end

#visit_array(array) ⇒ Object

Visit an array of elements



179
180
181
# File 'lib/coradoc/visitor.rb', line 179

def visit_array(array)
  array.each { |element| visit(element) }
end

#visit_bibliography(element) ⇒ Object

Visit a bibliography



144
145
146
# File 'lib/coradoc/visitor.rb', line 144

def visit_bibliography(element)
  visit_children(element.entries)
end

#visit_bibliography_entry(element) ⇒ Object

Visit a bibliography entry



149
150
151
# File 'lib/coradoc/visitor.rb', line 149

def visit_bibliography_entry(element)
  # BibliographyEntry is typically a leaf node
end

#visit_block(block) ⇒ Object

Visit a block element



69
70
71
# File 'lib/coradoc/visitor.rb', line 69

def visit_block(block)
  visit_children(block.children)
end

#visit_definition_item(element) ⇒ Object

Visit a definition item



139
140
141
# File 'lib/coradoc/visitor.rb', line 139

def visit_definition_item(element)
  # DefinitionItem is typically a leaf node
end

#visit_definition_list(element) ⇒ Object

Visit a definition list



134
135
136
# File 'lib/coradoc/visitor.rb', line 134

def visit_definition_list(element)
  visit_children(element.items)
end

#visit_element_attribute(element) ⇒ Object

Visit an element attribute



174
175
176
# File 'lib/coradoc/visitor.rb', line 174

def visit_element_attribute(element)
  # ElementAttribute is a leaf node
end

#visit_footnote(element) ⇒ Object

Visit a footnote



119
120
121
# File 'lib/coradoc/visitor.rb', line 119

def visit_footnote(element)
  # Footnote is typically a leaf node
end

#visit_footnote_reference(element) ⇒ Object

Visit a footnote reference



124
125
126
# File 'lib/coradoc/visitor.rb', line 124

def visit_footnote_reference(element)
  # FootnoteReference is typically a leaf node
end

#visit_image(image) ⇒ Object

Visit an image



104
105
106
# File 'lib/coradoc/visitor.rb', line 104

def visit_image(image)
  # Image is typically a leaf node
end

#visit_inline_element(element) ⇒ Object

Visit an inline element



74
75
76
# File 'lib/coradoc/visitor.rb', line 74

def visit_inline_element(element)
  visit_children(element.nested_elements)
end

#visit_list_block(list) ⇒ Object

Visit a list block



79
80
81
# File 'lib/coradoc/visitor.rb', line 79

def visit_list_block(list)
  visit_children(list.items)
end

#visit_list_item(item) ⇒ Object

Visit a list item



84
85
86
# File 'lib/coradoc/visitor.rb', line 84

def visit_list_item(item)
  visit_children(item.children)
end

#visit_metadata(element) ⇒ Object

Visit metadata



164
165
166
# File 'lib/coradoc/visitor.rb', line 164

def (element)
  visit_children(element.entries)
end

#visit_metadata_entry(element) ⇒ Object

Visit a metadata entry



169
170
171
# File 'lib/coradoc/visitor.rb', line 169

def (element)
  # MetadataEntry is a leaf node
end

#visit_structural_element(element) ⇒ Object

Visit a structural element (document, section)



64
65
66
# File 'lib/coradoc/visitor.rb', line 64

def visit_structural_element(element)
  visit_children(element.children)
end

#visit_table(table) ⇒ Object

Visit a table



89
90
91
# File 'lib/coradoc/visitor.rb', line 89

def visit_table(table)
  visit_children(table.rows)
end

#visit_table_cell(cell) ⇒ Object

Visit a table cell



99
100
101
# File 'lib/coradoc/visitor.rb', line 99

def visit_table_cell(cell)
  # TableCell typically contains text or nested elements
end

#visit_table_row(row) ⇒ Object

Visit a table row



94
95
96
# File 'lib/coradoc/visitor.rb', line 94

def visit_table_row(row)
  visit_children(row.cells)
end

#visit_term(term) ⇒ Object

Visit a term (definition list term)



109
110
111
# File 'lib/coradoc/visitor.rb', line 109

def visit_term(term)
  # Term is typically a leaf node
end

#visit_toc(element) ⇒ Object

Visit a table of contents



154
155
156
# File 'lib/coradoc/visitor.rb', line 154

def visit_toc(element)
  visit_children(element.entries)
end

#visit_toc_entry(element) ⇒ Object

Visit a TOC entry



159
160
161
# File 'lib/coradoc/visitor.rb', line 159

def visit_toc_entry(element)
  visit_children(element.children)
end

#visit_unknown(element) ⇒ Object

Visit an unknown element type



184
185
186
# File 'lib/coradoc/visitor.rb', line 184

def visit_unknown(element)
  # Override to handle unknown types
end