Class: PopulateMe::Variation

Inherits:
Struct
  • Object
show all
Defined in:
lib/populate_me/variation.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, ext, job_as_proc = nil, &job_as_block) ⇒ Variation

Simple class to deal with variations of an attachment Mainly variation of images using ImageMagick but it could be anything else like creating the pdf version of a text file



10
11
12
# File 'lib/populate_me/variation.rb', line 10

def initialize name, ext, job_as_proc=nil, &job_as_block
  super name, ext, job_as_proc||job_as_block
end

Instance Attribute Details

#extObject

Returns the value of attribute ext

Returns:

  • (Object)

    the current value of ext



3
4
5
# File 'lib/populate_me/variation.rb', line 3

def ext
  @ext
end

#jobObject

Returns the value of attribute job

Returns:

  • (Object)

    the current value of job



3
4
5
# File 'lib/populate_me/variation.rb', line 3

def job
  @job
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



3
4
5
# File 'lib/populate_me/variation.rb', line 3

def name
  @name
end

Class Method Details

.defaultObject



29
30
31
# File 'lib/populate_me/variation.rb', line 29

def default
  self.new_image_magick_job(:populate_me_thumb, :jpg, "-flatten -resize '400x230' -gravity center -extent 400x230")
end

.new_image_magick_job(name, ext, convert_string, options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/populate_me/variation.rb', line 16

def new_image_magick_job name, ext, convert_string, options={}
  o = {
    strip: true, progressive: true,
  }.merge(options)
  defaults = ""
  defaults << "-strip " if o[:strip]
  defaults << "-interlace Plane " if o[:progressive] and [:jpg,:jpeg].include?(ext.to_sym)
  job = lambda{ |src,dst|
    Kernel.system "convert \"#{src}\" #{defaults}#{convert_string} \"#{dst}\""
  }
  self.new name, ext, job
end