Class: Coradoc::CoreModel::StructuralElement

Inherits:
Base
  • Object
show all
Defined in:
lib/coradoc/core_model/structural_element.rb

Overview

Base class for structural elements

Represents document structure elements that organize content:

  • Sections (headings at various levels)

  • Document roots

  • Preamble

Structural elements can contain other elements (blocks, lists, etc.) and can be nested hierarchically to represent document structure.

This is a base class that can be extended in future phases to handle schema-specific structural requirements.

Examples:

Creating a section

section = CoreModel::StructuralElement.new(
  element_type: "section",
  level: 1,
  title: "Introduction",
  id: "introduction"
)

Creating a nested section structure

subsection = CoreModel::StructuralElement.new(
  element_type: "section",
  level: 2,
  title: "Background"
)
section = CoreModel::StructuralElement.new(
  element_type: "section",
  level: 1,
  title: "Introduction",
  children: [subsection]
)

Instance Attribute Summary collapse

Attributes inherited from Base

#element_attributes, #id, #metadata_entries, #title

Instance Method Summary collapse

Methods inherited from Base

#accept, #attr, #metadata, #semantically_equivalent?, #set_attr, #set_metadata

Instance Attribute Details

#attributesMetadata?

Returns document-level attributes (typed key-value pairs).

Returns:

  • (Metadata, nil)

    document-level attributes (typed key-value pairs)



58
# File 'lib/coradoc/core_model/structural_element.rb', line 58

attribute :attributes, Metadata

#childrenArray<Base>?

Returns child elements (sections, blocks, etc.).

Returns:

  • (Array<Base>, nil)

    child elements (sections, blocks, etc.)



54
# File 'lib/coradoc/core_model/structural_element.rb', line 54

attribute :children, Base, collection: true

#contentString?

Returns text content of the element.

Returns:

  • (String, nil)

    text content of the element



50
# File 'lib/coradoc/core_model/structural_element.rb', line 50

attribute :content, :string

#element_typeString?

Returns type of structural element (e.g., ‘section’, ‘header’, ‘preamble’, ‘division’).

Returns:

  • (String, nil)

    type of structural element (e.g., ‘section’, ‘header’, ‘preamble’, ‘division’)



42
# File 'lib/coradoc/core_model/structural_element.rb', line 42

attribute :element_type, :string

#levelInteger?

Returns hierarchical level (1-6 for sections).

Returns:

  • (Integer, nil)

    hierarchical level (1-6 for sections)



46
# File 'lib/coradoc/core_model/structural_element.rb', line 46

attribute :level, :integer

Instance Method Details

#document?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/coradoc/core_model/structural_element.rb', line 71

def document?
  element_type == 'document'
end

#heading_levelInteger

Heading level with sensible default

Returns:

  • (Integer)

    level, defaulting to 1 when unset



63
64
65
# File 'lib/coradoc/core_model/structural_element.rb', line 63

def heading_level
  level || 1
end

#section?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/coradoc/core_model/structural_element.rb', line 67

def section?
  element_type == 'section'
end