Class: Coradoc::CoreModel::StructuralElement
- Inherits:
-
Base
- Object
- Lutaml::Model::Serializable
- Base
- Coradoc::CoreModel::StructuralElement
- Includes:
- HasChildren
- Defined in:
- lib/coradoc/core_model/structural_element.rb
Overview
Base class for structural elements
Represents document structure elements that organize content. Typed subclasses (SectionElement, DocumentElement, etc.) express their role via the class hierarchy — the class IS the type.
Structural elements can contain other elements (blocks, lists, etc.) and can be nested hierarchically to represent document structure.
Direct Known Subclasses
DocumentElement, HeaderElement, PreambleElement, SectionElement
Instance Attribute Summary collapse
-
#attributes ⇒ Metadata?
Document-level attributes (typed key-value pairs).
-
#children ⇒ Array<Base>?
Child elements (sections, blocks, etc.).
-
#content ⇒ String?
Text content of the element.
-
#level ⇒ Integer?
Hierarchical level (1-6 for sections).
Attributes inherited from Base
#element_attributes, #id, #metadata_entries, #title
Class Method Summary collapse
Instance Method Summary collapse
- #document? ⇒ Boolean
-
#document_title? ⇒ Boolean
Override in subclasses that carry document-title semantics.
-
#element_type ⇒ Object
Derived element_type string for backward compatibility with templates and legacy consumers.
-
#empty_body? ⇒ Boolean
True when the body has no visible content anywhere in its subtree.
- #header? ⇒ Boolean
- #heading_level ⇒ Object
- #preamble? ⇒ Boolean
- #section? ⇒ Boolean
-
#visible_children ⇒ Object
Children that count as body content and aren’t whitespace-only.
Methods included from HasChildren
Methods inherited from Base
#accept, #attr, #body_content?, build, #flat_text, #metadata, #semantically_equivalent?, #set_attr, #set_metadata, #whitespace_only?
Instance Attribute Details
#attributes ⇒ Metadata?
Returns document-level attributes (typed key-value pairs).
33 |
# File 'lib/coradoc/core_model/structural_element.rb', line 33 attribute :attributes, Metadata |
#children ⇒ Array<Base>?
Returns child elements (sections, blocks, etc.).
29 |
# File 'lib/coradoc/core_model/structural_element.rb', line 29 attribute :children, Base, collection: true |
#content ⇒ String?
Returns text content of the element.
25 |
# File 'lib/coradoc/core_model/structural_element.rb', line 25 attribute :content, :string |
#level ⇒ Integer?
Returns hierarchical level (1-6 for sections).
21 |
# File 'lib/coradoc/core_model/structural_element.rb', line 21 attribute :level, :integer |
Class Method Details
.element_type_name ⇒ Object
93 94 95 |
# File 'lib/coradoc/core_model/structural_element.rb', line 93 def self.element_type_name nil end |
Instance Method Details
#document? ⇒ Boolean
43 44 45 |
# File 'lib/coradoc/core_model/structural_element.rb', line 43 def document? false end |
#document_title? ⇒ Boolean
Override in subclasses that carry document-title semantics. HeaderElement at level 0 represents the document title (‘= Title` in AsciiDoc). Consumers that walk the body — TOC builders, section numbering — skip these so the title is not counted as “section 1”. Polymorphic dispatch (vs. an is_a? guard at the call site) keeps the predicate open for future subclasses.
61 62 63 |
# File 'lib/coradoc/core_model/structural_element.rb', line 61 def document_title? false end |
#element_type ⇒ Object
Derived element_type string for backward compatibility with templates and legacy consumers. Subclasses override this.
89 90 91 |
# File 'lib/coradoc/core_model/structural_element.rb', line 89 def element_type self.class.element_type_name end |
#empty_body? ⇒ Boolean
True when the body has no visible content anywhere in its subtree. A document with only frontmatter + comments returns true; a document with one non-whitespace paragraph returns false.
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/coradoc/core_model/structural_element.rb', line 75 def empty_body? return true if children.nil? || children.empty? children.all? do |child| next true unless child.body_content? next true if child.whitespace_only? next child.empty_body? if child.is_a?(StructuralElement) false end end |
#header? ⇒ Boolean
51 52 53 |
# File 'lib/coradoc/core_model/structural_element.rb', line 51 def header? false end |
#heading_level ⇒ Object
35 36 37 |
# File 'lib/coradoc/core_model/structural_element.rb', line 35 def heading_level level || 1 end |
#preamble? ⇒ Boolean
47 48 49 |
# File 'lib/coradoc/core_model/structural_element.rb', line 47 def preamble? false end |
#section? ⇒ Boolean
39 40 41 |
# File 'lib/coradoc/core_model/structural_element.rb', line 39 def section? false end |
#visible_children ⇒ Object
Children that count as body content and aren’t whitespace-only. Derived from per-node Base#body_content? and Base#whitespace_only? predicates — no central walker, no is_a? switch to maintain.
68 69 70 |
# File 'lib/coradoc/core_model/structural_element.rb', line 68 def visible_children Array(children).select(&:body_content?).reject(&:whitespace_only?) end |