Class: Decidim::Exporters::Word

Inherits:
Exporter
  • Object
show all
Defined in:
lib/decidim/exporters/word.rb

Overview

Exports any serialized object (Hash) into a readable Excel file. It transforms the columns using slashes in a way that can be afterwards reconstructed into the original nested hash.

For example, `{ name: { ca: “Hola”, en: “Hello” } }` would result into the columns: `name/ca` and `name/es`.

It will maintain types like Integers, Floats & Dates so Excel can deal with them.

Instance Method Summary collapse

Instance Method Details

#exportObject

Public: Exports a file in an Excel readable format.

Returns an ExportData instance.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/decidim/exporters/word.rb', line 20

def export
  # @docx
  init_docx

  @component = collection.first.component
  @participatory_space = collection.first.participatory_space

  print_titles @component.name

  

  print_descriptions collection.first.participatory_space

  collection.each do |paragraph|
    next if paragraph.amended.present?

    print_paragraph paragraph
  end

  # @docx.p collection.inspect

  doxc_buffer = @docx.render
  doxc_buffer.rewind
  ExportData.new(doxc_buffer.sysread, "docx")
end