Class: Paperclip::XlsToCsv

Inherits:
Processor
  • Object
show all
Defined in:
lib/xls_to_csv-paperclip-processor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, options = {}, attachment = nil) ⇒ XlsToCsv

Returns a new instance of XlsToCsv.



5
6
7
8
9
10
11
12
13
# File 'lib/xls_to_csv-paperclip-processor.rb', line 5

def initialize(file, options = {}, attachment = nil)
  super

  @file           = file
  @params         = options[:params]
  @current_format = File.extname(@file.path)
  @basename       = File.basename(@file.path, @current_format)
  @format         = options[:format]
end

Instance Attribute Details

#fileObject

Returns the value of attribute file.



3
4
5
# File 'lib/xls_to_csv-paperclip-processor.rb', line 3

def file
  @file
end

#formatObject

Returns the value of attribute format.



3
4
5
# File 'lib/xls_to_csv-paperclip-processor.rb', line 3

def format
  @format
end

#paramsObject

Returns the value of attribute params.



3
4
5
# File 'lib/xls_to_csv-paperclip-processor.rb', line 3

def params
  @params
end

Instance Method Details

#makeObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/xls_to_csv-paperclip-processor.rb', line 15

def make
  src = @file
  dst = Tempfile.new([@basename, @format ? "#{@format}" : 'csv'].compact.join("."))

  begin      
    Paperclip.run(self.command, self.parameters(src, dst))      
  rescue StandardError => e
    raise "There was an error converting #{@basename} to csv: #{e.message}"
  end
  return dst
end