Class: Coradoc::Element::Inline::Span

Inherits:
Base
  • Object
show all
Defined in:
lib/coradoc/element/inline/span.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(text, options = {}) ⇒ Span

Returns a new instance of Span.



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

def initialize(text, options = {})
  @text = text
  @role = options.fetch(:role, nil)
  @attributes = options.fetch(:attributes, nil)
  @unconstrained = options.fetch(:unconstrained, false)
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



5
6
7
# File 'lib/coradoc/element/inline/span.rb', line 5

def attributes
  @attributes
end

#roleObject

Returns the value of attribute role.



5
6
7
# File 'lib/coradoc/element/inline/span.rb', line 5

def role
  @role
end

#textObject

Returns the value of attribute text.



5
6
7
# File 'lib/coradoc/element/inline/span.rb', line 5

def text
  @text
end

#unconstrainedObject

Returns the value of attribute unconstrained.



5
6
7
# File 'lib/coradoc/element/inline/span.rb', line 5

def unconstrained
  @unconstrained
end

Instance Method Details

#to_adocObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/coradoc/element/inline/span.rb', line 16

def to_adoc
  if @attributes
    attr_string = @attributes.to_adoc
    if @unconstrained
      "#{attr_string}###{@text}##"
    else
      "#{attr_string}##{@text}#"
    end
  elsif @role
    if @unconstrained
      "[.#{@role}]###{@text}##"
    else
      "[.#{@role}]##{@text}#"
    end
  else
    @text.to_s
  end
end