Class: Coradoc::CoreModel::StructuralElement

Inherits:
Base
  • Object
show all
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.

Instance Attribute Summary collapse

Attributes inherited from Base

#element_attributes, #id, #metadata_entries, #title

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HasChildren

#has_children?

Methods inherited from Base

#accept, #attr, #flat_text, #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)



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

attribute :attributes, Metadata

#childrenArray<Base>?

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

Returns:

  • (Array<Base>, nil)

    child elements (sections, blocks, etc.)



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

attribute :children, Base, collection: true

#contentString?

Returns text content of the element.

Returns:

  • (String, nil)

    text content of the element



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

attribute :content, :string

#levelInteger?

Returns hierarchical level (1-6 for sections).

Returns:

  • (Integer, nil)

    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_nameObject



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

def self.element_type_name
  nil
end

Instance Method Details

#document?Boolean

Returns:

  • (Boolean)


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

def document?
  false
end

#element_typeObject

Derived element_type string for backward compatibility with templates and legacy consumers. Subclasses override this.



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

def element_type
  self.class.element_type_name
end

#header?Boolean

Returns:

  • (Boolean)


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

def header?
  false
end

#heading_levelObject



35
36
37
# File 'lib/coradoc/core_model/structural_element.rb', line 35

def heading_level
  level || 1
end

#preamble?Boolean

Returns:

  • (Boolean)


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

def preamble?
  false
end

#section?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/coradoc/core_model/structural_element.rb', line 39

def section?
  false
end