Module: Coradoc::CoreModel::Builder::BlockBuilder Private

Included in:
Coradoc::CoreModel::Builder
Defined in:
lib/coradoc/core_model/builder/block_builder.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Block building module for Builder

Contains methods for building block elements from AST structures.

Instance Method Summary collapse

Instance Method Details

#build_annotation_block(ast) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Build annotation block



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/coradoc/core_model/builder/block_builder.rb', line 13

def build_annotation_block(ast)
  annotation_type = extract_annotation_type(ast)

  AnnotationBlock.new(
    annotation_type: annotation_type,
    annotation_label: extract_annotation_label(ast),
    delimiter_type: ast[:delimiter]&.to_s,
    delimiter_length: ast[:delimiter]&.to_s&.length || 4,
    content: extract_block_content(ast),
    lines: extract_block_lines(ast),
    title: ast[:title],
    id: ast[:id],
    attributes: build_attributes_private(ast[:attribute_list])
  )
end

#build_generic_block(ast) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Build generic block



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/coradoc/core_model/builder/block_builder.rb', line 30

def build_generic_block(ast)
  Block.new(
    delimiter_type: ast[:delimiter]&.to_s,
    delimiter_length: ast[:delimiter]&.to_s&.length || 4,
    content: extract_block_content(ast),
    lines: extract_block_lines(ast),
    title: ast[:title],
    id: ast[:id],
    attributes: build_attributes_private(ast[:attribute_list])
  )
end

#extract_block_content(ast) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Extract block content from various AST formats



43
44
45
46
47
48
49
50
51
52
# File 'lib/coradoc/core_model/builder/block_builder.rb', line 43

def extract_block_content(ast)
  return ast[:content] if ast[:content]

  if ast[:lines]
    lines = Array(ast[:lines])
    return lines.map { |line| extract_text_content(line) }.join("\n")
  end

  ''
end

#extract_block_lines(ast) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Extract block lines



55
56
57
58
59
# File 'lib/coradoc/core_model/builder/block_builder.rb', line 55

def extract_block_lines(ast)
  return [] unless ast[:lines]

  Array(ast[:lines]).map { |line| extract_text_content(line) }
end