Class: JCropper::CroppedImage

Inherits:
Object
  • Object
show all
Defined in:
lib/jcropper/cropped_image.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ CroppedImage

Returns a new instance of CroppedImage.



5
6
7
8
9
10
11
12
13
14
# File 'lib/jcropper/cropped_image.rb', line 5

def initialize(object)
  @object = object
  @attachment_name = object.class.jcropper_defs[:attachment]
  @style_name = object.jcropper_defs[:style]
  @attachment = object.send(attachment_name)  
  @coord_names = {}
  %w(x y w h).each{|v| @coord_names[v.to_sym] = JCropper.jattr(attachment_name, style_name, v)}

  @starting_crop = @coord_names.inject({}) {|h,pair| h.merge({ pair[0] => object.send("#{pair[1].to_s}_was") }) }
end

Instance Attribute Details

#attachmentObject (readonly)

Returns the value of attribute attachment.



3
4
5
# File 'lib/jcropper/cropped_image.rb', line 3

def attachment
  @attachment
end

#attachment_nameObject (readonly)

Returns the value of attribute attachment_name.



3
4
5
# File 'lib/jcropper/cropped_image.rb', line 3

def attachment_name
  @attachment_name
end

#coord_namesObject (readonly)

Returns the value of attribute coord_names.



3
4
5
# File 'lib/jcropper/cropped_image.rb', line 3

def coord_names
  @coord_names
end

#cropped_geometryObject (readonly)

Returns the value of attribute cropped_geometry.



3
4
5
# File 'lib/jcropper/cropped_image.rb', line 3

def cropped_geometry
  @cropped_geometry
end

#original_geometryObject (readonly)

CRZ these two might get out of date…



17
18
19
# File 'lib/jcropper/cropped_image.rb', line 17

def original_geometry
  @original_geometry
end

#starting_cropObject (readonly)

Returns the value of attribute starting_crop.



3
4
5
# File 'lib/jcropper/cropped_image.rb', line 3

def starting_crop
  @starting_crop
end

#style_nameObject (readonly)

Returns the value of attribute style_name.



3
4
5
# File 'lib/jcropper/cropped_image.rb', line 3

def style_name
  @style_name
end

Instance Method Details

#max_cropObject



29
30
31
# File 'lib/jcropper/cropped_image.rb', line 29

def max_crop
  [0, 0, original_geometry.width, original_geometry.height]
end

#target_geometryObject



25
26
27
# File 'lib/jcropper/cropped_image.rb', line 25

def target_geometry
  @target_geometry ||= Paperclip::Geometry.parse(@object.send(attachment_name).styles[style_name.to_sym][:geometry])
end