Class: Fzeet::Windows::HTMLElementCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/fzeet/windows/mshtml/Common.rb

Instance Method Summary collapse

Instance Method Details

#get(selector) ⇒ Object



874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
# File 'lib/fzeet/windows/mshtml/Common.rb', line 874

def get(selector)
  v = VARIANT.new

  case selector
  when String
    v[:vt] = VT_BSTR
    v[:bstrVal] = bstr = if selector[0] == '#'
      Windows.SysAllocString("#{selector[1..-1]}\0".encode('utf-16le'))
    else
      _tags = true
      Windows.SysAllocString("#{selector}\0".encode('utf-16le'))
    end
  when Integer
    v[:vt] = VT_I4; v[:intVal] = selector
  else raise ArgumentError
  end

  pdisp = nil

  FFI::MemoryPointer.new(:pointer) { |pdisp|
    (_tags) ? tags(v, pdisp) : item(v, VARIANT.new, pdisp)

    return nil if (pdisp = pdisp.read_pointer).null?

    disp = Dispatch.new(pdisp)

    return disp.QueryInstance((_tags) ? HTMLElementCollection : HTMLElement)
  }
ensure
  Windows.SysFreeString(bstr) if bstr
  pdisp.Release if pdisp && !pdisp.null?
end