Class: Decidim::OpenDataExporter
- Inherits:
-
Object
- Object
- Decidim::OpenDataExporter
- 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
-
#organization ⇒ Object
readonly
Returns the value of attribute organization.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #export ⇒ Object
-
#initialize(organization, path) ⇒ OpenDataExporter
constructor
Public: Initializes the class.
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. path end |
Instance Attribute Details
#organization ⇒ Object (readonly)
Returns the value of attribute organization.
12 13 14 |
# File 'app/services/decidim/open_data_exporter.rb', line 12 def organization @organization end |
#path ⇒ Object (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
#export ⇒ Object
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 |