class RSpecHTML::ReconstitutedElement
Reconstructs an HTML representation of an element from provided parameters.
Public Class Methods
new(tag, options)
click to toggle source
# File lib/rspec_html/reconstituted_element.rb, line 6 def initialize(tag, options) @tag = tag @options = options end
Public Instance Methods
to_s()
click to toggle source
# 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}#{formatted_attributes} />" unless @options&.key?(:text) "<#{name}#{formatted_attributes}>#{@options[:text]}</#{name}>" end
Private Instance Methods
formatted_attributes()
click to toggle source
# File lib/rspec_html/reconstituted_element.rb, line 32 def formatted_attributes mapped_attributes.empty? ? nil : " #{mapped_attributes.join(' ')}" end
mapped_attributes()
click to toggle source
# File lib/rspec_html/reconstituted_element.rb, line 22 def mapped_attributes return [] if @options.nil? @options.reject { |key| key.to_sym == :text }.map do |key, value| next %(#{key}="#{value}") unless key.to_sym == :class && value.is_a?(Array) %(#{key}="#{value.join(' ')}") end end