Class: RSpecHTML::Element

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/rspec_html/element.rb

Overview

HTML DOM element abstraction

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(element, name, options: {}, siblings: []) ⇒ Element

Returns a new instance of Element.



13
14
15
16
17
18
19
# File 'lib/rspec_html/element.rb', line 13

def initialize(element, name, options: {}, siblings: [])
  @name = name
  @element = element
  @options = options
  @siblings = siblings
  @search = Search.new(@element, @siblings)
end

Instance Attribute Details

#elementObject (readonly)

Returns the value of attribute element.



6
7
8
# File 'lib/rspec_html/element.rb', line 6

def element
  @element
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/rspec_html/element.rb', line 6

def name
  @name
end

Class Method Details

.reconstituted(tag, options = {}) ⇒ Object



49
50
51
# File 'lib/rspec_html/element.rb', line 49

def self.reconstituted(tag, options = {})
  ReconstitutedElement.new(tag, options).to_s
end

Instance Method Details

#inspectObject



28
29
30
# File 'lib/rspec_html/element.rb', line 28

def inspect
  "<#{self.class}::#{name.to_s.capitalize}>"
end

#present?Boolean Also known as: exist?

Returns:

  • (Boolean)


21
22
23
24
25
# File 'lib/rspec_html/element.rb', line 21

def present?
  return true if name == :document

  @search.present?
end

#reconstitutedObject



45
46
47
# File 'lib/rspec_html/element.rb', line 45

def reconstituted
  self.class.reconstituted(name, @options)
end

#to_sObject



32
33
34
# File 'lib/rspec_html/element.rb', line 32

def to_s
  @element.to_s
end