Class: Coradoc::Element::Paragraph

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

children_accessors, #children_accessors, declare_children, #simplify_block_content, visit, #visit

Constructor Details

#initialize(content, options = {}) ⇒ Paragraph

Returns a new instance of Paragraph.



8
9
10
11
12
13
14
# File 'lib/coradoc/element/paragraph.rb', line 8

def initialize(content, options = {})
  @content = content
  @meta = options.fetch(:meta, nil)
  id = options.fetch(:id, nil)
  @anchor = Inline::Anchor.new(id) if id
  @tdsinglepara = options.fetch(:tdsinglepara, nil)
end

Instance Attribute Details

#anchorObject

Returns the value of attribute anchor.



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

def anchor
  @anchor
end

#contentObject

Returns the value of attribute content.



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

def content
  @content
end

#tdsingleparaObject

Returns the value of attribute tdsinglepara.



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

def tdsinglepara
  @tdsinglepara
end

Instance Method Details

#idObject



16
17
18
# File 'lib/coradoc/element/paragraph.rb', line 16

def id
  content&.first&.id&.to_s
end

#textsObject



20
21
22
# File 'lib/coradoc/element/paragraph.rb', line 20

def texts
  content.map(&:content)
end

#to_adocObject



24
25
26
27
28
29
30
31
# File 'lib/coradoc/element/paragraph.rb', line 24

def to_adoc
  anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}\n"
  if @tdsinglepara
    anchor.to_s << Coradoc::Generator.gen_adoc(@content).strip
  else
    "\n\n#{anchor}" << Coradoc::Generator.gen_adoc(@content).strip << "\n\n"
  end
end