Class: Coradoc::Element::Section

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, options = {}) ⇒ Section

Returns a new instance of Section.



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

def initialize(title, options = {})
  @title = title
  @id = options.fetch(:id, nil)
  @contents = options.fetch(:contents, [])
  @sections = options.fetch(:sections, [])
  @anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
end

Instance Attribute Details

#contentsObject (readonly)

Returns the value of attribute contents.



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

def contents
  @contents
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#sectionsObject (readonly)

Returns the value of attribute sections.



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

def sections
  @sections
end

#titleObject (readonly)

Returns the value of attribute title.



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

def title
  @title
end

Instance Method Details

#contentObject



18
19
20
21
22
# File 'lib/coradoc/element/section.rb', line 18

def content
  if contents.count == 1 && contents.first.is_a?(Coradoc::Element::Paragraph)
    contents.first
  end
end

#glossariesObject



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

def glossaries
  @glossaries ||= extract_glossaries
end

#to_adocObject



24
25
26
27
28
# File 'lib/coradoc/element/section.rb', line 24

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