Class: RSpecHTML::ReconstitutedElement

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_html/reconstituted_element.rb

Overview

Reconstructs an HTML representation of an element from provided parameters.

Instance Method Summary collapse

Constructor Details

#initialize(tag, options) ⇒ ReconstitutedElement

Returns a new instance of ReconstitutedElement.



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

def initialize(tag, options)
  @tag = tag
  @options = options
end

Instance Method Details

#to_sObject



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

def to_s
  name = @tag.to_s.downcase
  return '#document' if name == 'document'
  return name if name == 'document'
  return "<#{name}#{shorthand_options} />" if @options.is_a?(String)
  return "<#{name}#{formatted_attributes} />" unless @options&.key?(:text)

  "<#{name}#{formatted_attributes}>#{@options[:text]}</#{name}>"
end