Class: Alchemy::ImageCropperSettings

Inherits:
Object
  • Object
show all
Defined in:
app/models/alchemy/image_cropper_settings.rb

Overview

Settings for the graphical JS image cropper

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(render_size:, default_crop_from:, default_crop_size:, fixed_ratio:, image_width:, image_height:) ⇒ ImageCropperSettings

Returns a new instance of ImageCropperSettings.


8
9
10
11
12
13
14
15
# File 'app/models/alchemy/image_cropper_settings.rb', line 8

def initialize(render_size:, default_crop_from:, default_crop_size:, fixed_ratio:, image_width:, image_height:)
  @render_size = render_size || [0, 0]
  @fixed_ratio = fixed_ratio
  @image_width = image_width.to_i
  @image_height = image_height.to_i
  @default_crop_from = default_crop_from || [0, 0]
  @default_crop_size = default_crop_size || [@image_width, @image_height]
end

Instance Attribute Details

#default_crop_fromObject (readonly)

Returns the value of attribute default_crop_from.


6
7
8
# File 'app/models/alchemy/image_cropper_settings.rb', line 6

def default_crop_from
  @default_crop_from
end

#default_crop_sizeObject (readonly)

Returns the value of attribute default_crop_size.


6
7
8
# File 'app/models/alchemy/image_cropper_settings.rb', line 6

def default_crop_size
  @default_crop_size
end

#fixed_ratioObject (readonly)

Returns the value of attribute fixed_ratio.


6
7
8
# File 'app/models/alchemy/image_cropper_settings.rb', line 6

def fixed_ratio
  @fixed_ratio
end

#image_heightObject (readonly)

Returns the value of attribute image_height.


6
7
8
# File 'app/models/alchemy/image_cropper_settings.rb', line 6

def image_height
  @image_height
end

#image_widthObject (readonly)

Returns the value of attribute image_width.


6
7
8
# File 'app/models/alchemy/image_cropper_settings.rb', line 6

def image_width
  @image_width
end

#render_sizeObject (readonly)

Returns the value of attribute render_size.


6
7
8
# File 'app/models/alchemy/image_cropper_settings.rb', line 6

def render_size
  @render_size
end

Instance Method Details

#[](key) ⇒ Object


28
29
30
# File 'app/models/alchemy/image_cropper_settings.rb', line 28

def [](key)
  to_h[key]
end

#to_hObject


17
18
19
20
21
22
23
24
25
26
# File 'app/models/alchemy/image_cropper_settings.rb', line 17

def to_h
  return {} if image_width.zero? || image_height.zero?

  {
    min_size: large_enough? ? min_size : false,
    ratio: ratio,
    default_box: default_box,
    image_size: [image_width, image_height],
  }.freeze
end