File: image.rb

package info (click to toggle)
ruby-rghost 0.9.9-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,188 kB
  • sloc: ruby: 3,374; makefile: 6; sh: 1
file content (26 lines) | stat: -rw-r--r-- 688 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
require "rghost/ps_object"
# Super class of GIF and JPEG.
class RGhost::Image < RGhost::PsObject
  DEFAULT_OPTIONS = {x: :limit_left, y: 1, zoom: 100, rotate: 0}

  def initialize(image_path, options = {})
    super("")
    @options = DEFAULT_OPTIONS.dup.merge(options)
    @file = image_path
  end

  # Facade method for load image by file extension. Uses Eps, Gif and Jpeg class. Accepts gif, jpeg, jpg and eps
  def self.for(path, options = {})
    clazz = case path
    when /gif$/i
      RGhost::Gif
    when /jpe?g$/i
      RGhost::Jpeg
    when /(eps|template)$/i
      RGhost::Eps
    else raise NameError.new("Unsupported format")
    end

    clazz.new(path, options)
  end
end