Class: Coradoc::Element::Title

Inherits:
Object
  • Object
show all
Defined in:
lib/coradoc/element/title.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content, level, options = {}) ⇒ Title

Returns a new instance of Title.



6
7
8
9
10
11
12
13
# File 'lib/coradoc/element/title.rb', line 6

def initialize(content, level, options = {})
  @level_int = level
  @level_int = level.length if level.is_a?(String)
  @content = content
  @id = options.fetch(:id, nil)
  @anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
  @line_break = options.fetch(:line_break, "")
end

Instance Attribute Details

#contentObject (readonly) Also known as: text

Returns the value of attribute content.



4
5
6
# File 'lib/coradoc/element/title.rb', line 4

def content
  @content
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/coradoc/element/title.rb', line 4

def id
  @id
end

#line_breakObject (readonly)

Returns the value of attribute line_break.



4
5
6
# File 'lib/coradoc/element/title.rb', line 4

def line_break
  @line_break
end

Instance Method Details

#levelObject



15
16
17
# File 'lib/coradoc/element/title.rb', line 15

def level
  @level_str ||= level_from_string
end

#to_adocObject



19
20
21
22
23
24
# File 'lib/coradoc/element/title.rb', line 19

def to_adoc
  anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}\n"
  content = Coradoc::Generator.gen_adoc(@content)
  level_str = "=" * (@level_int + 1)
  content = ["\n", anchor, level_str, ' ', content, "\n"].join("")
end