Class: Coradoc::Markdown::Base
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Coradoc::Markdown::Base
- Defined in:
- lib/coradoc/markdown/model/base.rb
Overview
Base class for all Markdown model objects.
The Base class provides common functionality for all document model elements, including serialization support and tree traversal.
Direct Known Subclasses
Abbreviation, AttributeList, Blockquote, Code, CodeBlock, CrossReference, DefinitionItem, DefinitionList, DefinitionTerm, Document, Emphasis, Extension, Footnote, FootnoteReference, Heading, Highlight, HorizontalRule, Image, Link, List, ListItem, Math, NamedValue, Paragraph, Strikethrough, Strong, Subscript, Superscript, Table, Text, Underline
Class Method Summary collapse
-
.visit(element) {|element, :post| ... } ⇒ Object
Visit pattern for traversing the document tree.
Instance Method Summary collapse
Class Method Details
.visit(element) {|element, :post| ... } ⇒ Object
Visit pattern for traversing the document tree
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/coradoc/markdown/model/base.rb', line 25 def self.visit(element, &block) return element if element.nil? element = yield element, :pre element = case element when self element.visit(&block) when Array element.map { |child| visit(child, &block) }.flatten.compact when Hash result = {} element.each { |k, v| result[k] = visit(v, &block) } result else element end yield element, :post end |
Instance Method Details
#visit(&block) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/coradoc/markdown/model/base.rb', line 44 def visit(&block) self.class.attributes.each_key do |attr_name| child = public_send(attr_name) result = self.class.visit(child, &block) public_send(:"#{attr_name}=", result) if result != child end self end |