Class: Dommy::DOMRect

Inherits:
Object
  • Object
show all
Defined in:
lib/dommy/element.rb

Overview

Stub ‘DOMRect` for `getBoundingClientRect` — no layout engine, so all values are 0. Consumer code that uses these for relative positioning sees zeroed values; absolute layout assertions need the real browser.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x: 0, y: 0, width: 0, height: 0) ⇒ DOMRect

Returns a new instance of DOMRect.



623
624
625
626
627
628
# File 'lib/dommy/element.rb', line 623

def initialize(x: 0, y: 0, width: 0, height: 0)
  @x = x
  @y = y
  @width = width
  @height = height
end

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



621
622
623
# File 'lib/dommy/element.rb', line 621

def height
  @height
end

#widthObject (readonly)

Returns the value of attribute width.



621
622
623
# File 'lib/dommy/element.rb', line 621

def width
  @width
end

#xObject (readonly)

Returns the value of attribute x.



621
622
623
# File 'lib/dommy/element.rb', line 621

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



621
622
623
# File 'lib/dommy/element.rb', line 621

def y
  @y
end

Instance Method Details

#__js_get__(key) ⇒ Object



646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
# File 'lib/dommy/element.rb', line 646

def __js_get__(key)
  case key
  when "x", "left"
    @x
  when "y", "top"
    @y
  when "width"
    @width
  when "height"
    @height
  when "right"
    @x + @width
  when "bottom"
    @y + @height
  end
end

#bottomObject



642
643
644
# File 'lib/dommy/element.rb', line 642

def bottom
  @y + @height
end

#js_null?Boolean

Returns:

  • (Boolean)


663
664
665
# File 'lib/dommy/element.rb', line 663

def js_null?
  false
end

#leftObject



634
635
636
# File 'lib/dommy/element.rb', line 634

def left
  @x
end

#rightObject



638
639
640
# File 'lib/dommy/element.rb', line 638

def right
  @x + @width
end

#topObject



630
631
632
# File 'lib/dommy/element.rb', line 630

def top
  @y
end