Class: Coradoc::AsciiDoc::Model::Title

Inherits:
Base
  • Object
show all
Includes:
Anchorable
Defined in:
lib/coradoc/asciidoc/model/title.rb

Overview

Title element for sections and document headers.

Represents a title with optional level information. Titles are used by sections to define their heading level and text content.

Examples:

Create a level 1 title

title = Coradoc::AsciiDoc::Model::Title.new(
  content: [Coradoc::AsciiDoc::Model::TextElement.new("Chapter 1")],
  level_int: 0
)
title.to_adoc # => "= Chapter 1\n"

Create a level 2 title

title = Coradoc::AsciiDoc::Model::Title.new(
  content: [Coradoc::AsciiDoc::Model::TextElement.new("Section 1.1")],
  level_int: 1
)
title.to_adoc # => "== Section 1.1\n"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Anchorable

#default_anchor, #gen_anchor, included, #initialize

Methods inherited from Base

#block_level?, #inline?, #serialize_content, #simplify_block_content, #to_adoc, #to_h, visit, #visit

Instance Attribute Details

#contentArray<TextElement> (readonly) Also known as: text

Returns Title text content (can include inline formatting).

Returns:

  • (Array<TextElement>)

    Title text content (can include inline formatting)



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/coradoc/asciidoc/model/title.rb', line 36

class Title < Base
  include Coradoc::AsciiDoc::Model::Anchorable

  attribute :id, :string
  attribute :content, Coradoc::AsciiDoc::Model::TextElement, collection: true
  # attribute :level, :string
  attribute :level_int, :integer
  attribute :line_break, :string, default: -> { "\n" }
  attribute :style, :string

  alias text content

  # Convert title content to string
  # @return [String] The title text
  def to_s
    case content
    when String
      content
    when Array
      content.map do |item|
        item.is_a?(Coradoc::AsciiDoc::Model::TextElement) ? item.content.to_s : item.to_s
      end.join
    else
      content.to_s
    end
  end

  def level_str
    return '' if level_int.nil?

    if level_int <= 5
      '=' * (level_int + 1)
    else
      '======'
    end
  end

  def style_str
    return '' if level_int.nil?

    _style = [style]
    _style << "level=#{level_int}" if level_int > 5
    _style = _style.compact.join(',')

    _style.empty? ? '' : "[#{_style}]\n"
  end
end

#idString? (readonly)

Returns Optional identifier for the title.

Returns:

  • (String, nil)

    Optional identifier for the title



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/coradoc/asciidoc/model/title.rb', line 36

class Title < Base
  include Coradoc::AsciiDoc::Model::Anchorable

  attribute :id, :string
  attribute :content, Coradoc::AsciiDoc::Model::TextElement, collection: true
  # attribute :level, :string
  attribute :level_int, :integer
  attribute :line_break, :string, default: -> { "\n" }
  attribute :style, :string

  alias text content

  # Convert title content to string
  # @return [String] The title text
  def to_s
    case content
    when String
      content
    when Array
      content.map do |item|
        item.is_a?(Coradoc::AsciiDoc::Model::TextElement) ? item.content.to_s : item.to_s
      end.join
    else
      content.to_s
    end
  end

  def level_str
    return '' if level_int.nil?

    if level_int <= 5
      '=' * (level_int + 1)
    else
      '======'
    end
  end

  def style_str
    return '' if level_int.nil?

    _style = [style]
    _style << "level=#{level_int}" if level_int > 5
    _style = _style.compact.join(',')

    _style.empty? ? '' : "[#{_style}]\n"
  end
end

#level_intInteger? (readonly)

Returns Heading level (0-5 for standard, 6+ uses style attribute).

Returns:

  • (Integer, nil)

    Heading level (0-5 for standard, 6+ uses style attribute)



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/coradoc/asciidoc/model/title.rb', line 36

class Title < Base
  include Coradoc::AsciiDoc::Model::Anchorable

  attribute :id, :string
  attribute :content, Coradoc::AsciiDoc::Model::TextElement, collection: true
  # attribute :level, :string
  attribute :level_int, :integer
  attribute :line_break, :string, default: -> { "\n" }
  attribute :style, :string

  alias text content

  # Convert title content to string
  # @return [String] The title text
  def to_s
    case content
    when String
      content
    when Array
      content.map do |item|
        item.is_a?(Coradoc::AsciiDoc::Model::TextElement) ? item.content.to_s : item.to_s
      end.join
    else
      content.to_s
    end
  end

  def level_str
    return '' if level_int.nil?

    if level_int <= 5
      '=' * (level_int + 1)
    else
      '======'
    end
  end

  def style_str
    return '' if level_int.nil?

    _style = [style]
    _style << "level=#{level_int}" if level_int > 5
    _style = _style.compact.join(',')

    _style.empty? ? '' : "[#{_style}]\n"
  end
end

#line_breakString (readonly)

Returns Line break character after title (default: newline).

Returns:

  • (String)

    Line break character after title (default: newline)



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/coradoc/asciidoc/model/title.rb', line 36

class Title < Base
  include Coradoc::AsciiDoc::Model::Anchorable

  attribute :id, :string
  attribute :content, Coradoc::AsciiDoc::Model::TextElement, collection: true
  # attribute :level, :string
  attribute :level_int, :integer
  attribute :line_break, :string, default: -> { "\n" }
  attribute :style, :string

  alias text content

  # Convert title content to string
  # @return [String] The title text
  def to_s
    case content
    when String
      content
    when Array
      content.map do |item|
        item.is_a?(Coradoc::AsciiDoc::Model::TextElement) ? item.content.to_s : item.to_s
      end.join
    else
      content.to_s
    end
  end

  def level_str
    return '' if level_int.nil?

    if level_int <= 5
      '=' * (level_int + 1)
    else
      '======'
    end
  end

  def style_str
    return '' if level_int.nil?

    _style = [style]
    _style << "level=#{level_int}" if level_int > 5
    _style = _style.compact.join(',')

    _style.empty? ? '' : "[#{_style}]\n"
  end
end

#styleString? (readonly)

Returns Optional style attribute for title formatting.

Returns:

  • (String, nil)

    Optional style attribute for title formatting



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/coradoc/asciidoc/model/title.rb', line 36

class Title < Base
  include Coradoc::AsciiDoc::Model::Anchorable

  attribute :id, :string
  attribute :content, Coradoc::AsciiDoc::Model::TextElement, collection: true
  # attribute :level, :string
  attribute :level_int, :integer
  attribute :line_break, :string, default: -> { "\n" }
  attribute :style, :string

  alias text content

  # Convert title content to string
  # @return [String] The title text
  def to_s
    case content
    when String
      content
    when Array
      content.map do |item|
        item.is_a?(Coradoc::AsciiDoc::Model::TextElement) ? item.content.to_s : item.to_s
      end.join
    else
      content.to_s
    end
  end

  def level_str
    return '' if level_int.nil?

    if level_int <= 5
      '=' * (level_int + 1)
    else
      '======'
    end
  end

  def style_str
    return '' if level_int.nil?

    _style = [style]
    _style << "level=#{level_int}" if level_int > 5
    _style = _style.compact.join(',')

    _style.empty? ? '' : "[#{_style}]\n"
  end
end

Instance Method Details

#level_strObject



63
64
65
66
67
68
69
70
71
# File 'lib/coradoc/asciidoc/model/title.rb', line 63

def level_str
  return '' if level_int.nil?

  if level_int <= 5
    '=' * (level_int + 1)
  else
    '======'
  end
end

#style_strObject



73
74
75
76
77
78
79
80
81
# File 'lib/coradoc/asciidoc/model/title.rb', line 73

def style_str
  return '' if level_int.nil?

  _style = [style]
  _style << "level=#{level_int}" if level_int > 5
  _style = _style.compact.join(',')

  _style.empty? ? '' : "[#{_style}]\n"
end

#to_sString

Convert title content to string

Returns:

  • (String)

    The title text



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/coradoc/asciidoc/model/title.rb', line 50

def to_s
  case content
  when String
    content
  when Array
    content.map do |item|
      item.is_a?(Coradoc::AsciiDoc::Model::TextElement) ? item.content.to_s : item.to_s
    end.join
  else
    content.to_s
  end
end