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 (= Title, == Title, === Title, etc.)

  • Headers

  • Document divisions

  • 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

#childrenArray<Base>?

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

Returns:

  • (Array<Base>, nil)

    child elements (sections, blocks, etc.)



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

attribute :children, Base, collection: true

#contentString?

Returns text content of the element.

Returns:

  • (String, nil)

    text content of the element



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

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’)



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

attribute :element_type, :string

#levelInteger?

Returns hierarchical level (1-6 for sections).

Returns:

  • (Integer, nil)

    hierarchical level (1-6 for sections)



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

attribute :level, :integer

Instance Method Details

#document?Boolean

Returns:

  • (Boolean)


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

def document?
  element_type == 'document'
end

#heading_levelInteger

Heading level with sensible default

Returns:

  • (Integer)

    level, defaulting to 1 when unset



60
61
62
# File 'lib/coradoc/core_model/structural_element.rb', line 60

def heading_level
  level || 1
end

#section?Boolean

Returns:

  • (Boolean)


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

def section?
  element_type == 'section'
end