Class: Monet::Image
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #basename ⇒ Object
- #diff_path ⇒ Object
- #flagged? ⇒ Boolean
-
#initialize(path) ⇒ Image
constructor
A new instance of Image.
- #is_diff? ⇒ Boolean
- #name ⇒ Object
- #root_dir ⇒ Object
- #thumbnail!(save_to = nil) ⇒ Object
- #to_image ⇒ Object
- #width ⇒ Object
Constructor Details
#initialize(path) ⇒ Image
Returns a new instance of Image.
11 12 13 |
# File 'lib/monet/image.rb', line 11 def initialize(path) @path = File. path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/monet/image.rb', line 9 def path @path end |
Instance Method Details
#basename ⇒ Object
35 36 37 |
# File 'lib/monet/image.rb', line 35 def basename @path.split(File::SEPARATOR)[-2..-1].join(File::SEPARATOR) end |
#diff_path ⇒ Object
19 20 21 |
# File 'lib/monet/image.rb', line 19 def diff_path @path.gsub(".png", "-diff.png") end |
#flagged? ⇒ Boolean
23 24 25 |
# File 'lib/monet/image.rb', line 23 def flagged? File.exists? diff_path end |
#is_diff? ⇒ Boolean
15 16 17 |
# File 'lib/monet/image.rb', line 15 def is_diff? name.include? "-diff" end |
#name ⇒ Object
31 32 33 |
# File 'lib/monet/image.rb', line 31 def name @name ||= File.basename @path end |
#root_dir ⇒ Object
43 44 45 |
# File 'lib/monet/image.rb', line 43 def root_dir File.dirname @path end |
#thumbnail!(save_to = nil) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/monet/image.rb', line 47 def thumbnail!(save_to=nil) img = to_image short_edge = [img.width, img.height].min cropped = img.crop(0, 0, short_edge, short_edge) resized = cropped.resize(200, 200) if save_to.nil? save_to = @path.gsub(".png", "-thumb.png") else save_to = File.join save_to, File.basename(@path) end save_dir = File.dirname(save_to) FileUtils.mkdir_p save_dir unless Dir.exists?(save_dir) resized.save save_to save_to end |
#to_image ⇒ Object
39 40 41 |
# File 'lib/monet/image.rb', line 39 def to_image ChunkyPNG::Image.from_file(@path) end |
#width ⇒ Object
27 28 29 |
# File 'lib/monet/image.rb', line 27 def width @width ||= File.basename(@path, ".png").split("-").last.to_i end |