Class: Thumbnailer::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/thumbnailer/base.rb

Direct Known Subclasses

File, Files, PDF

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/thumbnailer/base.rb', line 11

def initialize(options = {})
  @options      = options
  @object       = options[:object]
  @ratio        = options[:ratio] || 2
  @width        = options[:width]
  @height       = options[:height]
  @image_width  = nil
  @image_height = nil
  @prefix       = options[:prefix] || 'thumb_'
  @dir          = options[:dir]
  @sequence     = nil

  extract_image_size
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



9
10
11
# File 'lib/thumbnailer/base.rb', line 9

def dir
  @dir
end

#heightObject (readonly)

Returns the value of attribute height.



9
10
11
# File 'lib/thumbnailer/base.rb', line 9

def height
  @height
end

#image_heightObject (readonly)

Returns the value of attribute image_height.



9
10
11
# File 'lib/thumbnailer/base.rb', line 9

def image_height
  @image_height
end

#image_widthObject (readonly)

Returns the value of attribute image_width.



9
10
11
# File 'lib/thumbnailer/base.rb', line 9

def image_width
  @image_width
end

#prefixObject (readonly)

Returns the value of attribute prefix.



9
10
11
# File 'lib/thumbnailer/base.rb', line 9

def prefix
  @prefix
end

#sequenceObject (readonly)

Returns the value of attribute sequence.



9
10
11
# File 'lib/thumbnailer/base.rb', line 9

def sequence
  @sequence
end

#widthObject (readonly)

Returns the value of attribute width.



9
10
11
# File 'lib/thumbnailer/base.rb', line 9

def width
  @width
end

Instance Method Details

#createObject



33
34
35
# File 'lib/thumbnailer/base.rb', line 33

def create
  write
end

#outputObject



26
27
28
29
30
31
# File 'lib/thumbnailer/base.rb', line 26

def output
  path = "#{@dir}/#{@prefix}#{@file}"
  path = path.gsub(/\.(\w+)$/, ".#{@options[:format]}") if @options[:format].to_s.size > 0
  path = insert_page(path)
  path
end

#writeObject



37
38
39
40
# File 'lib/thumbnailer/base.rb', line 37

def write
  resize
  @object.write(output)
end