Class: Privatize::Image
- Inherits:
-
Object
- Object
- Privatize::Image
- Defined in:
- lib/privatize/image.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #dirname ⇒ Object
- #ext ⇒ Object
- #filename ⇒ Object
- #image ⇒ Object
- #info ⇒ Object
-
#initialize(path, options = {}) ⇒ Image
constructor
A new instance of Image.
- #output_path(method) ⇒ Object
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, ={} @path = path @output = [:output] || nil end |
Instance Attribute Details
#output ⇒ Object (readonly)
Returns the value of attribute output.
5 6 7 |
# File 'lib/privatize/image.rb', line 5 def output @output end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/privatize/image.rb', line 5 def path @path end |
Class Method Details
.effects ⇒ Object
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
#dirname ⇒ Object
36 37 38 |
# File 'lib/privatize/image.rb', line 36 def dirname File.dirname(@path) end |
#ext ⇒ Object
32 33 34 |
# File 'lib/privatize/image.rb', line 32 def ext File.extname(@path) end |
#filename ⇒ Object
28 29 30 |
# File 'lib/privatize/image.rb', line 28 def filename File.basename(@path, ".*") end |
#image ⇒ Object
19 20 21 |
# File 'lib/privatize/image.rb', line 19 def image @image ||= MiniMagick::Image.new(@path) end |
#info ⇒ Object
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 |