Sha256: c80c48d9ec0fd4d0669a9d5a01fdeef5acac3eebf0e6d2eef1c2f64b44edcca4

Contents?: true

Size: 503 Bytes

Versions: 3

Compression:

Stored size: 503 Bytes

Contents

module CsvMaker
  CHARACTERS_SET = [('a'..'z'), ('A'..'Z')].map{|i| i.to_a}.flatten

  def self.create_file(dir, original_filename)
    filename = rnd_prefix << sanitize_filename(original_filename)
    path = File.join(dir, filename)

    File.new(path, 'wb')
  end

  def self.sanitize_filename(filename)
    just_filename = File.basename(filename)
    just_filename.gsub(/[^\w\.\-]/,'_')
  end

  def self.rnd_prefix
    (0..5).map { CHARACTERS_SET[rand(CHARACTERS_SET.length)] }.join << '_'
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
csv_uploader_tool-0.1.2 lib/csv_uploader_tool/csv_maker.rb
csv_uploader_tool-0.1.1 lib/csv_uploader_tool/csv_maker.rb
csv_uploader_tool-0.1.0 lib/csv_uploader_tool/csv_maker.rb