Class: Coradoc::Element::Paragraph

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Paragraph.



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

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 (readonly)

Returns the value of attribute anchor.



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

def anchor
  @anchor
end

#contentObject (readonly)

Returns the value of attribute content.



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

def content
  @content
end

#tdsingleparaObject (readonly)

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



14
15
16
# File 'lib/coradoc/element/paragraph.rb', line 14

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

#textsObject



18
19
20
# File 'lib/coradoc/element/paragraph.rb', line 18

def texts
  content.map(&:content)
end

#to_adocObject



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

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