Class: Decidim::Votings::Census::AccessCodesExporter
- Inherits:
-
Object
- Object
- Decidim::Votings::Census::AccessCodesExporter
- Includes:
- TranslatableAttributes
- Defined in:
- app/services/decidim/votings/census/access_codes_exporter.rb
Overview
Public: Generates a 7z(seven zip) file with data files ready to be persisted somewhere so users can download their data.
The 7z file wraps a ZIP file which finally contains the data files.
Constant Summary collapse
- FILE_NAME_PATTERN =
"%{voting_name}-voting-access-codes.csv"
Instance Attribute Summary collapse
-
#dataset ⇒ Object
readonly
Returns the value of attribute dataset.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #export ⇒ Object
-
#initialize(dataset, path, password) ⇒ AccessCodesExporter
constructor
Public: Initializes the class.
Constructor Details
#initialize(dataset, path, password) ⇒ AccessCodesExporter
Public: Initializes the class.
dataset - The Voting::Census::Dataset to export the access codes for. path - The String path where to write the zip file. password - The password to protect the zip file.
25 26 27 28 29 |
# File 'app/services/decidim/votings/census/access_codes_exporter.rb', line 25 def initialize(dataset, path, password) @dataset = dataset @path = File. path @password = password end |
Instance Attribute Details
#dataset ⇒ Object (readonly)
Returns the value of attribute dataset.
18 19 20 |
# File 'app/services/decidim/votings/census/access_codes_exporter.rb', line 18 def dataset @dataset end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
18 19 20 |
# File 'app/services/decidim/votings/census/access_codes_exporter.rb', line 18 def password @password end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
18 19 20 |
# File 'app/services/decidim/votings/census/access_codes_exporter.rb', line 18 def path @path end |
Instance Method Details
#export ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'app/services/decidim/votings/census/access_codes_exporter.rb', line 31 def export dirname = File.dirname(@path) FileUtils.mkdir_p(dirname) unless File.directory?(dirname) File.open(@path, "wb") do |file| SevenZipRuby::Writer.open(file, password:) do |szw| szw.header_encryption = true szw.add_data(csv_data.read, format(FILE_NAME_PATTERN, voting_name: translated_attribute(dataset.voting.title).parameterize)) end end end |