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.



861
862
863
864
865
866
# File 'lib/dommy/element.rb', line 861

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.



859
860
861
# File 'lib/dommy/element.rb', line 859

def height
  @height
end

#widthObject (readonly)

Returns the value of attribute width.



859
860
861
# File 'lib/dommy/element.rb', line 859

def width
  @width
end

#xObject (readonly)

Returns the value of attribute x.



859
860
861
# File 'lib/dommy/element.rb', line 859

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



859
860
861
# File 'lib/dommy/element.rb', line 859

def y
  @y
end

Instance Method Details

#__js_get__(key) ⇒ Object



884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
# File 'lib/dommy/element.rb', line 884

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



880
881
882
# File 'lib/dommy/element.rb', line 880

def bottom
  @y + @height
end

#js_null?Boolean

Returns:

  • (Boolean)


901
902
903
# File 'lib/dommy/element.rb', line 901

def js_null?
  false
end

#leftObject



872
873
874
# File 'lib/dommy/element.rb', line 872

def left
  @x
end

#rightObject



876
877
878
# File 'lib/dommy/element.rb', line 876

def right
  @x + @width
end

#topObject



868
869
870
# File 'lib/dommy/element.rb', line 868

def top
  @y
end