Class: Libis::Format::Converter::ImageAssembler

Inherits:
Base
  • Object
show all
Defined in:
lib/libis/format/converter/image_assembler.rb

Overview

noinspection RubyTooManyInstanceVariablesInspection,DuplicatedCode

Instance Attribute Summary

Attributes inherited from Base

#flags, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#check_file_exist, inherited, #initialize, using_temp, #using_temp

Constructor Details

This class inherits a constructor from Libis::Format::Converter::Base

Class Method Details

.categoryObject



33
34
35
# File 'lib/libis/format/converter/image_assembler.rb', line 33

def self.category
  :assembler
end

.input_typesObject



24
25
26
# File 'lib/libis/format/converter/image_assembler.rb', line 24

def self.input_types
  [:TIFF, :JPG, :PNG, :BMP, :GIF, :PDF, :JP2]
end

.output_types(format = nil) ⇒ Object



28
29
30
31
# File 'lib/libis/format/converter/image_assembler.rb', line 28

def self.output_types(format = nil)
  return [] unless input_types.include?(format) if format
  [:PDF, :TIFF, :GIF, :PBM, :PGM, :PPM]
end

Instance Method Details

#convert(source, target, format, opts = {}) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/libis/format/converter/image_assembler.rb', line 45

def convert(source, target, format, opts = {})
  super

  FileUtils.mkpath(File.dirname(target))

  if source.is_a? Array
    assemble(source, target, format)
  elsif File.directory?(source)
    source_list = Dir[File.join(source, '**', '*')].reject {|p| File.directory? p}
    assemble(source_list, target, format)
  else
    image = MiniMagick::Image.open(source) {|b| b.quiet}
    if image.pages.size > 1
      assemble(image.pages.map {|page| page.path}, target, format)
    else
      assemble([source], target, format)
    end
  end

  target

end

#image_assemble(_) ⇒ Object



37
38
39
# File 'lib/libis/format/converter/image_assembler.rb', line 37

def image_assemble(_)
  #force usage of this converter
end

#quiet(v) ⇒ Object



41
42
43
# File 'lib/libis/format/converter/image_assembler.rb', line 41

def quiet(v)
  @quiet = !!v
end