Class: Miso::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/miso/processor.rb,
lib/miso/processor/core_image.rb,
lib/miso/processor/image_magick.rb,
lib/miso/processor/graphics_magick.rb

Direct Known Subclasses

CoreImage, ImageMagick

Defined Under Namespace

Classes: CoreImage, GraphicsMagick, ImageMagick

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input_file) ⇒ Processor

Returns a new instance of Processor.

Raises:

  • (Errno::ENOENT)


40
41
42
43
# File 'lib/miso/processor.rb', line 40

def initialize(input_file)
  @input_file = File.expand_path(input_file)
  raise Errno::ENOENT, @input_file unless File.exist?(@input_file)
end

Class Attribute Details

.processor_classObject

The default processor class.

Returns either the assigned processor, or otherwise finds the first processor, that is available on the machine, from the processor_classes array.



19
20
21
22
23
# File 'lib/miso/processor.rb', line 19

def processor_class
  @processor_class ||= processor_classes.find { |c| c.available? }
  raise "None of the Miso::Processor classes are available." unless @processor_class
  @processor_class
end

.processor_classesObject

The list of processor classes.

When no explicit processor_class is set this list is iterated, from first to last, and the first available processor on the machine is used.



29
30
31
# File 'lib/miso/processor.rb', line 29

def processor_classes
  @processor_classes ||= [CoreImage, GraphicsMagick, ImageMagick]
end

Instance Attribute Details

#input_fileObject (readonly)

Returns the value of attribute input_file.



38
39
40
# File 'lib/miso/processor.rb', line 38

def input_file
  @input_file
end

Class Method Details

.available?Boolean

Returns:

  • (Boolean)

Raises:



33
34
35
# File 'lib/miso/processor.rb', line 33

def available?
  raise NotImplementedError, "The class `#{name}' does not implement ::available?."
end

Instance Method Details

#auto_orientObject



53
54
55
# File 'lib/miso/processor.rb', line 53

def auto_orient
  raise NotImplementedError, "The class `#{self.class.name}' does not implement #auto_orient."
end

#crop(width, height) ⇒ Object



45
46
47
# File 'lib/miso/processor.rb', line 45

def crop(width, height)
  raise NotImplementedError, "The class `#{self.class.name}' does not implement #crop."
end

#dimensionsObject



57
58
59
# File 'lib/miso/processor.rb', line 57

def dimensions
  raise NotImplementedError, "The class `#{self.class.name}' does not implement #dimensions."
end

#fit(width, height) ⇒ Object



49
50
51
# File 'lib/miso/processor.rb', line 49

def fit(width, height)
  raise NotImplementedError, "The class `#{self.class.name}' does not implement #fit."
end

#heightObject



69
70
71
# File 'lib/miso/processor.rb', line 69

def height
  dimensions.last
end

#widthObject



65
66
67
# File 'lib/miso/processor.rb', line 65

def width
  dimensions.first
end

#write(output_file) ⇒ Object



61
62
63
# File 'lib/miso/processor.rb', line 61

def write(output_file)
  raise NotImplementedError, "The class `#{self.class.name}' does not implement #write."
end