Class: Canon::Comparison::MatchOptions::XmlResolver
- Inherits:
-
BaseResolver
- Object
- BaseResolver
- Canon::Comparison::MatchOptions::XmlResolver
- Defined in:
- lib/canon/comparison/match_options/xml_resolver.rb
Overview
XML/HTML-specific match options resolver
Constant Summary collapse
- FORMAT_DEFAULTS =
Format-specific defaults for XML/HTML
{ html: { preprocessing: :rendered, text_content: :normalize, structural_whitespace: :normalize, attribute_presence: :strict, attribute_order: :ignore, attribute_values: :strict, element_position: :ignore, comments: :ignore, }, xml: { preprocessing: :none, text_content: :strict, structural_whitespace: :strict, attribute_presence: :strict, attribute_order: :ignore, attribute_values: :strict, element_position: :strict, comments: :strict, }, }.freeze
- MATCH_PROFILES =
Predefined match profiles for XML/HTML
{ # Strict: Match exactly as written in source (XML default) strict: { preprocessing: :none, text_content: :strict, structural_whitespace: :strict, attribute_presence: :strict, attribute_order: :strict, attribute_values: :strict, element_position: :strict, comments: :strict, }, # Rendered: Match rendered output (HTML default) # Mimics CSS whitespace collapsing rendered: { preprocessing: :none, text_content: :normalize, structural_whitespace: :normalize, attribute_presence: :strict, attribute_order: :strict, attribute_values: :strict, element_position: :strict, comments: :ignore, }, # HTML4: Match HTML4 rendered output # HTML4 rendering normalizes attribute whitespace html4: { preprocessing: :rendered, text_content: :normalize, structural_whitespace: :normalize, attribute_presence: :strict, attribute_order: :strict, attribute_values: :normalize, element_position: :ignore, comments: :ignore, }, # HTML5: Match HTML5 rendered output (same as rendered) html5: { preprocessing: :rendered, text_content: :normalize, structural_whitespace: :normalize, attribute_presence: :strict, attribute_order: :strict, attribute_values: :strict, element_position: :ignore, comments: :ignore, }, # Spec-friendly: Formatting doesn't matter # Uses :rendered preprocessing for HTML which normalizes via to_html spec_friendly: { preprocessing: :rendered, text_content: :normalize, structural_whitespace: :ignore, attribute_presence: :strict, attribute_order: :ignore, attribute_values: :normalize, element_position: :ignore, comments: :ignore, }, # Content-only: Only content matters content_only: { preprocessing: :c14n, text_content: :normalize, structural_whitespace: :ignore, attribute_presence: :strict, attribute_order: :ignore, attribute_values: :normalize, element_position: :ignore, comments: :ignore, }, }.freeze
Class Method Summary collapse
-
.format_defaults(format) ⇒ Hash
Get format-specific default options.
-
.get_profile_options(profile) ⇒ Hash
Get options for a named profile.
-
.match_dimensions ⇒ Object
Matching dimensions for XML/HTML (collectively exhaustive).
Methods inherited from BaseResolver
Class Method Details
.format_defaults(format) ⇒ Hash
Get format-specific default options
130 131 132 |
# File 'lib/canon/comparison/match_options/xml_resolver.rb', line 130 def format_defaults(format) FORMAT_DEFAULTS[format]&.dup || FORMAT_DEFAULTS[:xml].dup end |
.get_profile_options(profile) ⇒ Hash
Get options for a named profile
139 140 141 142 143 144 145 146 |
# File 'lib/canon/comparison/match_options/xml_resolver.rb', line 139 def (profile) unless MATCH_PROFILES.key?(profile) raise Canon::Error, "Unknown match profile: #{profile}. " \ "Valid profiles: #{MATCH_PROFILES.keys.join(', ')}" end MATCH_PROFILES[profile].dup end |
.match_dimensions ⇒ Object
Matching dimensions for XML/HTML (collectively exhaustive)
114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/canon/comparison/match_options/xml_resolver.rb', line 114 def match_dimensions %i[ text_content structural_whitespace attribute_presence attribute_order attribute_values element_position comments ].freeze end |