Class: Coradoc::Element::ListItemDefinition

Inherits:
Base
  • Object
show all
Defined in:
lib/coradoc/element/list_item_definition.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(terms, contents, options = {}) ⇒ ListItemDefinition

Returns a new instance of ListItemDefinition.



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

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

Instance Attribute Details

#contentsObject

Returns the value of attribute contents.



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

def contents
  @contents
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#termsObject

Returns the value of attribute terms.



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

def terms
  @terms
end

Instance Method Details

#to_adoc(delimiter) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/coradoc/element/list_item_definition.rb', line 15

def to_adoc(delimiter)
  anchor = @anchor.nil? ? "" : @anchor.to_adoc.to_s
  content = ""
  if (@terms.is_a?(Array) && @terms.size == 1) || !@terms.is_a?(Array)
    t = Coradoc::Generator.gen_adoc(@terms)
    content << "#{anchor}#{t}#{delimiter} "
  else
    @terms.map do |term|
      t = Coradoc::Generator.gen_adoc(term)
      content << "#{t}#{delimiter}\n"
    end
  end
  d = Coradoc::Generator.gen_adoc(@contents)
  content << "#{d}\n"
end