class ODSExtractor::CSVOutput
Public Class Methods
new(csv_directory_path)
click to toggle source
# File lib/ods_extractor/csv_output.rb, line 2 def initialize(csv_directory_path) require "csv" @csv_directory_path = csv_directory_path end
Public Instance Methods
end_sheet()
click to toggle source
# 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)
click to toggle source
# 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.expand_path(sheet_name)) "#{sanitized_sheet_name}.csv" end
start_sheet(sheet_name)
click to toggle source
# 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)
click to toggle source
# 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