Class: Privatize::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/privatize/image.rb

Direct Known Subclasses

Pixelate

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, options = {}) ⇒ Image

Returns a new instance of Image.



7
8
9
10
# File 'lib/privatize/image.rb', line 7

def initialize path, options={}
  @path = path
  @output = options[:output] || nil
end

Instance Attribute Details

#outputObject (readonly)

Returns the value of attribute output.



5
6
7
# File 'lib/privatize/image.rb', line 5

def output
  @output
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/privatize/image.rb', line 5

def path
  @path
end

Class Method Details

.effectsObject



13
14
15
16
# File 'lib/privatize/image.rb', line 13

def effects
  klasses = ObjectSpace.each_object(Class).select { |klass| klass < self }
  klasses.map {|e| e.to_s.split('::').last.downcase }     
end

Instance Method Details

#dirnameObject



36
37
38
# File 'lib/privatize/image.rb', line 36

def dirname
  File.dirname(@path)
end

#extObject



32
33
34
# File 'lib/privatize/image.rb', line 32

def ext
  File.extname(@path)
end

#filenameObject



28
29
30
# File 'lib/privatize/image.rb', line 28

def filename
  File.basename(@path, ".*")
end

#imageObject



19
20
21
# File 'lib/privatize/image.rb', line 19

def image
  @image ||= MiniMagick::Image.new(@path)
end

#infoObject



23
24
25
26
# File 'lib/privatize/image.rb', line 23

def info
  @info ||= MiniMagick::Image::Info.new(@path)
  %w{format width height size human_size}.inject({}) { |r,x| r.update(x => @info.cheap_info(x)) }
end

#output_path(method) ⇒ Object



40
41
42
43
# File 'lib/privatize/image.rb', line 40

def output_path method
  @output = Pathname.new(@output).directory? ? "#{@output}/#{filename}_#{method}_#{Time.now.to_i}#{ext}" : @output
  @output || "#{dirname}/#{filename}_#{method}_#{Time.now.to_i}#{ext}"
end