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

access_children, #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
15
# File 'lib/coradoc/element/paragraph.rb', line 8

def initialize(content, options = {})
  @content = content
  @id = options.fetch(:id, nil)
  @anchor = Inline::Anchor.new(@id) if @id
  @title = options.fetch(:title, nil)
  @attributes = options.fetch(:attributes, nil)
  @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



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

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

#textsObject



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

def texts
  content.map(&:content)
end

#to_adocObject



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

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