Sha256: 53cbf4ce808ae5b374a03134f82eb736bf3e1b8965b6dc87d2d328308ff52675

Contents?: true

Size: 596 Bytes

Versions: 1

Compression:

Stored size: 596 Bytes

Contents

require "SimpleCSVUploder/version"

module SimpleCSVUploder
  def initialize(params = {})
    @file = params.delete(:file)
    super
    if @file
      self.filename = sanitize_filename(@file.original_filename)
      self.content_type = @file.content_type
      self.file_contents = @file.read
    end
  end

  private

  def sanitize_filename(filename)
    return File.basename(filename)
  end

  NUM_BYTES_IN_MEGABYTE = 1048576
  def file_size_under_one_mb
    if (@file.size.to_f / NUM_BYTES_IN_MEGABYTE) > 1
      errors.add(:file, 'File size cannot be over one megabyte.')
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
SimpleCSVUploder-0.1.0 lib/SimpleCSVUploder.rb