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.
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.
16 17 18 19 |
# File 'app/services/decidim/open_data_exporter.rb', line 16 def initialize(organization, path) @organization = organization @path = File. path end |
Instance Attribute Details
#organization ⇒ Object (readonly)
Returns the value of attribute organization.
10 11 12 |
# File 'app/services/decidim/open_data_exporter.rb', line 10 def organization @organization end |
#path ⇒ Object (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
#export ⇒ Object
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 |