Class: Puppeteer::ElementHandle::Point

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

Overview

A class to represent (x, y)-coordinates supporting + and / operators.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x:, y:) ⇒ Point

Returns a new instance of Point.

Parameters:

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


5
6
7
8
# File 'lib/puppeteer/element_handle/point.rb', line 5

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

Instance Attribute Details

#xNumeric (readonly)

Returns the value of attribute x.

Returns:

  • (Numeric)


35
36
37
# File 'lib/puppeteer/element_handle/point.rb', line 35

def x
  @x
end

#yNumeric (readonly)

Returns the value of attribute y.

Returns:

  • (Numeric)


35
36
37
# File 'lib/puppeteer/element_handle/point.rb', line 35

def y
  @y
end

Instance Method Details

#+(other) ⇒ Puppeteer::ElementHandle::Point



10
11
12
13
14
15
# File 'lib/puppeteer/element_handle/point.rb', line 10

def +(other)
  Point.new(
    x: @x + other.x,
    y: @y + other.y,
  )
end

#/(num) ⇒ Puppeteer::ElementHandle::Point

Parameters:

  • num (Numeric)

Returns:



17
18
19
20
21
22
# File 'lib/puppeteer/element_handle/point.rb', line 17

def /(num)
  Point.new(
    x: @x / num,
    y: @y / num,
  )
end

#==(other) ⇒ Boolean

Parameters:

  • other (Object)

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
32
33
# File 'lib/puppeteer/element_handle/point.rb', line 24

def ==(other)
  case other
  when Hash
    @x == other[:x] && @y == other[:y]
  when Point
    @x == other.x && @y == other.y
  else
    super
  end
end