Class: RSpecHTML::Element
- Inherits:
-
Object
- Object
- RSpecHTML::Element
- Extended by:
- Forwardable
- Defined in:
- lib/rspec_html/element.rb
Overview
HTML DOM element abstraction
Instance Attribute Summary collapse
-
#element ⇒ Object
readonly
Returns the value of attribute element.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#search ⇒ Object
readonly
Returns the value of attribute search.
Class Method Summary collapse
Instance Method Summary collapse
- #html_path ⇒ Object
-
#initialize(element, name, options: {}, siblings: []) ⇒ Element
constructor
A new instance of Element.
- #inspect ⇒ Object
- #open ⇒ Object
- #present? ⇒ Boolean (also: #exist?)
- #reconstituted ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(element, name, options: {}, siblings: []) ⇒ Element
Returns a new instance of Element.
17 18 19 20 21 22 23 |
# File 'lib/rspec_html/element.rb', line 17 def initialize(element, name, options: {}, siblings: []) @name = name @element = element @options = @siblings = siblings || [] @search = Search.new(@element, @siblings, self) end |
Instance Attribute Details
#element ⇒ Object (readonly)
Returns the value of attribute element.
6 7 8 |
# File 'lib/rspec_html/element.rb', line 6 def element @element end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/rspec_html/element.rb', line 6 def name @name end |
#search ⇒ Object (readonly)
Returns the value of attribute search.
6 7 8 |
# File 'lib/rspec_html/element.rb', line 6 def search @search end |
Class Method Details
.reconstituted(tag, options = {}) ⇒ Object
64 65 66 |
# File 'lib/rspec_html/element.rb', line 64 def self.reconstituted(tag, = {}) ReconstitutedElement.new(tag, ).to_s end |
Instance Method Details
#html_path ⇒ Object
29 30 31 32 33 |
# File 'lib/rspec_html/element.rb', line 29 def html_path @html_path ||= Pathname.new(Dir.mktmpdir('rspec-html')).join('document.html').tap do |path| path.write(@element.inner_html) end end |
#inspect ⇒ Object
42 43 44 |
# File 'lib/rspec_html/element.rb', line 42 def inspect reconstituted end |
#open ⇒ Object
25 26 27 |
# File 'lib/rspec_html/element.rb', line 25 def open Browser.open(html_path) end |
#present? ⇒ Boolean Also known as: exist?
35 36 37 38 39 |
# File 'lib/rspec_html/element.rb', line 35 def present? return true if name == :document @search.present? end |
#reconstituted ⇒ Object
60 61 62 |
# File 'lib/rspec_html/element.rb', line 60 def reconstituted self.class.reconstituted(name, @options) end |
#to_s ⇒ Object
46 47 48 |
# File 'lib/rspec_html/element.rb', line 46 def to_s @element.to_s end |