Class: Puppeteer::ElementHandle::Offset

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

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.



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

#xObject (readonly)

Returns the value of attribute x.



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

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



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

def y
  @y
end

Class Method Details

.from(offset) ⇒ Object



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