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.



16
17
18
19
# File 'app/services/decidim/open_data_exporter.rb', line 16

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

Instance Attribute Details

#organizationObject (readonly)

Returns the value of attribute organization.



10
11
12
# File 'app/services/decidim/open_data_exporter.rb', line 10

def organization
  @organization
end

#pathObject (readonly)

Returns the value of attribute path.



10
11
12
# File 'app/services/decidim/open_data_exporter.rb', line 10

def path
  @path
end

Instance Method Details

#exportObject



21
22
23
24
25
# File 'app/services/decidim/open_data_exporter.rb', line 21

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