Class: Coradoc::Element::DocumentAttributes

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

Returns a new instance of DocumentAttributes.



8
9
10
11
# File 'lib/coradoc/element/document_attributes.rb', line 8

def initialize(data = {}, options = {})
  @data = data
  @options = options
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



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

def data
  @data
end

Instance Method Details

#to_adocObject



19
20
21
22
23
24
# File 'lib/coradoc/element/document_attributes.rb', line 19

def to_adoc
  to_hash.map do |key, value|
    v = value.to_s.empty? ? "" : " #{value}"
    ":#{key}:#{v}\n"
  end.join + "\n"
end

#to_hashObject



13
14
15
16
17
# File 'lib/coradoc/element/document_attributes.rb', line 13

def to_hash
  @data.to_h do |attribute|
    [attribute.key.to_s, attribute.value.to_s.gsub("'", "")]
  end
end