Class: Puppeteer::ElementHandle::BoxModel

Inherits:
Object
  • Object
show all
Defined in:
lib/puppeteer/element_handle/box_model.rb

Constant Summary collapse

QUAD_ATTRIBUTE_NAMES =
%i(content padding border margin)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result_model, offset:) ⇒ BoxModel

Returns a new instance of BoxModel.

Parameters:

  • result (Hash)
  • offset (Point)


6
7
8
9
10
11
12
13
14
15
16
# File 'lib/puppeteer/element_handle/box_model.rb', line 6

def initialize(result_model, offset:)
  QUAD_ATTRIBUTE_NAMES.each do |attr_name|
    quad = result_model[attr_name.to_s]
    instance_variable_set(
      :"@#{attr_name}",
      quad.each_slice(2).map { |x, y| Point.new(x: x, y: y) + offset },
    )
  end
  @width = result_model['width']
  @height = result_model['height']
end

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



18
19
20
# File 'lib/puppeteer/element_handle/box_model.rb', line 18

def height
  @height
end

#widthObject (readonly)

Returns the value of attribute width.



18
19
20
# File 'lib/puppeteer/element_handle/box_model.rb', line 18

def width
  @width
end