Class: ODSExtractor::CSVOutput
- Inherits:
-
Object
- Object
- ODSExtractor::CSVOutput
- Defined in:
- lib/ods_extractor/csv_output.rb
Instance Method Summary collapse
- #end_sheet ⇒ Object
-
#initialize(csv_directory_path) ⇒ CSVOutput
constructor
A new instance of CSVOutput.
- #sheet_name_to_csv_file_name(sheet_name) ⇒ Object
- #start_sheet(sheet_name) ⇒ Object
- #write_row(row_values) ⇒ Object
Constructor Details
#initialize(csv_directory_path) ⇒ CSVOutput
Returns a new instance of CSVOutput.
2 3 4 5 |
# File 'lib/ods_extractor/csv_output.rb', line 2 def initialize(csv_directory_path) require "csv" @csv_directory_path = csv_directory_path end |
Instance Method Details
#end_sheet ⇒ Object
15 16 17 |
# File 'lib/ods_extractor/csv_output.rb', line 15 def end_sheet @write_output_file.close end |
#sheet_name_to_csv_file_name(sheet_name) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/ods_extractor/csv_output.rb', line 19 def sheet_name_to_csv_file_name(sheet_name) # This is a subtle spot where there can be a security problem - we take an unsanitized sheet name # and we include it in a filesystem path. So some precaution needs to be taken. sanitized_sheet_name = File.basename(File.(sheet_name)) "#{sanitized_sheet_name}.csv" end |
#start_sheet(sheet_name) ⇒ Object
7 8 9 |
# File 'lib/ods_extractor/csv_output.rb', line 7 def start_sheet(sheet_name) @write_output_file = File.open(File.join(@csv_directory_path, sheet_name_to_csv_file_name(sheet_name)), "wb") end |
#write_row(row_values) ⇒ Object
11 12 13 |
# File 'lib/ods_extractor/csv_output.rb', line 11 def write_row(row_values) @write_output_file << CSV.generate_line(row_values, force_quotes: true) # => "foo,0\n" end |