Class: Decidim::OpenDataExporter

Inherits:
Object
  • Object
show all
Defined in:
app/services/decidim/open_data_exporter.rb

Overview

Public: It generates a ZIP file with Open Data CSV files ready to be uploaded somewhere so users can download an organization data.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(organization, path) ⇒ OpenDataExporter

Public: Initializes the class.

organization - The Organization to export the data from. path - The String path where to write the zip file.



14
15
16
17
# File 'app/services/decidim/open_data_exporter.rb', line 14

def initialize(organization, path)
  @organization = organization
  @path = File.expand_path path
end

Instance Attribute Details

#organizationObject (readonly)

Returns the value of attribute organization.



8
9
10
# File 'app/services/decidim/open_data_exporter.rb', line 8

def organization
  @organization
end

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'app/services/decidim/open_data_exporter.rb', line 8

def path
  @path
end

Instance Method Details

#exportObject



19
20
21
22
23
# File 'app/services/decidim/open_data_exporter.rb', line 19

def export
  dirname = File.dirname(path)
  FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
  File.open(path, "wb") { |file| file.write(data) }
end