Class: Docxtor::ReferenceBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/docxtor/reference_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(elements) ⇒ ReferenceBuilder

Returns a new instance of ReferenceBuilder.



5
6
7
8
# File 'lib/docxtor/reference_builder.rb', line 5

def initialize elements
  @elements = elements
  @elements.each_with_index { |el, i| el.reference_id = "rId#{i+1}" }
end

Instance Attribute Details

#elementsObject

Returns the value of attribute elements.



3
4
5
# File 'lib/docxtor/reference_builder.rb', line 3

def elements
  @elements
end

Instance Method Details

#contentObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/docxtor/reference_builder.rb', line 14

def content
  xml = ::Builder::XmlMarkup.new

  xml.instruct! :xml, :version => "1.0", :encoding=>"UTF-8", :standalone => "yes"
  xml.Relationships "xmlns" => "http://schemas.openxmlformats.org/package/2006/relationships" do |xml|
    elements.each do |element|
      xml.Relationship "Id" => element.reference_id,
                       "Target" => element.name,
                       "Type" => element.reference_type
    end
  end

  xml.target!
end

#filenameObject



10
11
12
# File 'lib/docxtor/reference_builder.rb', line 10

def filename
  "word/_rels/document.xml.rels"
end