Class: Coradoc::CoreModel::Block

Inherits:
Base
  • Object
show all
Includes:
ChildrenContent
Defined in:
lib/coradoc/core_model/block.rb

Overview

Generic block model

Represents all block-level elements in a format-neutral way. Typed subclasses (SourceBlock, QuoteBlock, etc.) express their semantic identity via the class hierarchy — the class IS the type. Generic Block instances use block_semantic_type for typing.

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 ChildrenContent

#children=, #flat_text, included, #initialize, #renderable_content, #to_hash

Methods inherited from Base

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

Instance Attribute Details

#block_semantic_typeString?

Returns semantic type for generic Block instances. Typed subclasses should not override this — use the class instead.

Returns:

  • (String, nil)

    semantic type for generic Block instances. Typed subclasses should not override this — use the class instead.



34
# File 'lib/coradoc/core_model/block.rb', line 34

attribute :block_semantic_type, :string

#contentString?

Returns the block’s text content (simple string) For mixed content with inline elements, use children instead.

Returns:

  • (String, nil)

    the block’s text content (simple string) For mixed content with inline elements, use children instead.



44
# File 'lib/coradoc/core_model/block.rb', line 44

attribute :content, :string

#delimiter_typeString?

Returns raw delimiter for round-trip fidelity. Format-specific; CoreModel does NOT derive semantics from this.

Returns:

  • (String, nil)

    raw delimiter for round-trip fidelity. Format-specific; CoreModel does NOT derive semantics from this.



39
# File 'lib/coradoc/core_model/block.rb', line 39

attribute :delimiter_type, :string

#languageString?

Returns language identifier for source code blocks.

Returns:

  • (String, nil)

    language identifier for source code blocks



52
# File 'lib/coradoc/core_model/block.rb', line 52

attribute :language, :string

#linesArray<String>?

Returns individual lines of content.

Returns:

  • (Array<String>, nil)

    individual lines of content



48
# File 'lib/coradoc/core_model/block.rb', line 48

attribute :lines, :string, collection: true

Class Method Details

.semantic_typeObject



15
16
17
# File 'lib/coradoc/core_model/block.rb', line 15

def semantic_type
  nil
end

Instance Method Details

#element_typeObject

Derived element_type string for backward compatibility. Returns the semantic type as a string, derived from the class or block_semantic_type.



27
28
29
# File 'lib/coradoc/core_model/block.rb', line 27

def element_type
  resolve_semantic_type&.to_s
end

#resolve_semantic_typeObject



20
21
22
# File 'lib/coradoc/core_model/block.rb', line 20

def resolve_semantic_type
  self.class.semantic_type || block_semantic_type&.to_sym
end