Class: ImageGenie::Convert

Inherits:
Command
  • Object
show all
Defined in:
lib/image_genie/convert.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(src, options = {}) ⇒ Convert

Returns a new instance of Convert.

Raises:

  • (Errno::ENOENT)


13
14
15
16
17
18
19
20
21
# File 'lib/image_genie/convert.rb', line 13

def initialize(src,options={})
  self.src = src
  self.options = options
  self.src_format = File.extname(src.path).downcase.gsub(/\.|\?/,'')
  logger.info("#{self.class.name} Attempting to convert #{src.path}")
  raise Errno::ENOENT,"#{src.path}" unless File.exists?(src.path)
  self.temp_image_file = Tempfile.new([src.original_filename,".#{src_format}"]) 
  super(self)
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/image_genie/convert.rb', line 4

def options
  @options
end

#srcObject

Returns the value of attribute src.



4
5
6
# File 'lib/image_genie/convert.rb', line 4

def src
  @src
end

#src_formatObject

Returns the value of attribute src_format.



4
5
6
# File 'lib/image_genie/convert.rb', line 4

def src_format
  @src_format
end

#temp_image_fileObject

Returns the value of attribute temp_image_file.



4
5
6
# File 'lib/image_genie/convert.rb', line 4

def temp_image_file
  @temp_image_file
end

Instance Method Details

#outputObject



6
7
8
9
10
11
# File 'lib/image_genie/convert.rb', line 6

def output
  while line = stdout.gets
    temp_image_file.puts line
  end
  temp_image_file.rewind
end

#runObject



23
24
25
26
# File 'lib/image_genie/convert.rb', line 23

def run
  execute("#{path_for(:convert)} #{make_flags(options)} #{src_format}:#{src.path} #{src_format}:-")      
  temp_image_file
end