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.

Constant Summary collapse

FILE_NAME_PATTERN =
"%{host}-open-data-%{entity}.csv"

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.



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

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

Instance Attribute Details

#organizationObject (readonly)

Returns the value of attribute organization.



12
13
14
# File 'app/services/decidim/open_data_exporter.rb', line 12

def organization
  @organization
end

#pathObject (readonly)

Returns the value of attribute path.



12
13
14
# File 'app/services/decidim/open_data_exporter.rb', line 12

def path
  @path
end

Instance Method Details

#exportObject



23
24
25
26
27
# File 'app/services/decidim/open_data_exporter.rb', line 23

def export
  dirname = File.dirname(path)
  FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
  File.binwrite(path, data)
end