Class: Puppeteer::ElementHandle::Offset

Inherits:
Object
  • Object
show all
Defined in:
lib/puppeteer/element_handle/offset.rb,
sig/_supplementary.rbs

Overview

A class to represent (x, y)-offset coordinates

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x:, y:) ⇒ Offset

Returns a new instance of Offset.

Parameters:

  • x: (Numeric)
  • y: (Numeric)


4
5
6
7
# File 'lib/puppeteer/element_handle/offset.rb', line 4

def initialize(x:, y:)
  @x = x
  @y = y
end

Instance Attribute Details

#xNumeric (readonly)

Returns the value of attribute x.

Returns:

  • (Numeric)


26
27
28
# File 'lib/puppeteer/element_handle/offset.rb', line 26

def x
  @x
end

#yNumeric (readonly)

Returns the value of attribute y.

Returns:

  • (Numeric)


26
27
28
# File 'lib/puppeteer/element_handle/offset.rb', line 26

def y
  @y
end

Class Method Details

.from(offset) ⇒ Puppeteer::ElementHandle::Offset?

Parameters:

Returns:



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/puppeteer/element_handle/offset.rb', line 9

def self.from(offset)
  case offset
  when nil
    nil
  when Hash
    if offset[:x] && offset[:y]
      Offset.new(x: offset[:x], y: offset[:y])
    else
      raise ArgumentError.new('offset parameter must have x, y coordinates')
    end
  when Offset
    offset
  else
    raise ArgumentError.new('Offset.from(Hash|Offset)')
  end
end