Class: PureDocx::Constructors::ImageSize

Inherits:
Object
  • Object
show all
Defined in:
lib/puredocx/constructors/image_size.rb

Constant Summary collapse

MAX_IMAGE_WIDTH =
650
PX_EMU =
8625

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arguments = {}) ⇒ ImageSize

Returns a new instance of ImageSize.



9
10
11
12
# File 'lib/puredocx/constructors/image_size.rb', line 9

def initialize(arguments = {})
  @width, @height           = arguments[:user_params]
  @real_width, @real_height = arguments[:real_params]
end

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



7
8
9
# File 'lib/puredocx/constructors/image_size.rb', line 7

def height
  @height
end

#real_heightObject (readonly)

Returns the value of attribute real_height.



7
8
9
# File 'lib/puredocx/constructors/image_size.rb', line 7

def real_height
  @real_height
end

#real_widthObject (readonly)

Returns the value of attribute real_width.



7
8
9
# File 'lib/puredocx/constructors/image_size.rb', line 7

def real_width
  @real_width
end

#widthObject (readonly)

Returns the value of attribute width.



7
8
9
# File 'lib/puredocx/constructors/image_size.rb', line 7

def width
  @width
end

Instance Method Details

#prepare_sizeObject



14
15
16
17
18
# File 'lib/puredocx/constructors/image_size.rb', line 14

def prepare_size
  new_width, new_height = set_new_size_params
  new_width, new_height = scaled_params(new_width, new_height) if new_width > MAX_IMAGE_WIDTH
  { width: new_width, height: new_height }.map { |key, value| [key, (value * PX_EMU)] }.to_h
end