Class: Canon::Comparison::Dimensions::CommentsDimension
- Inherits:
-
BaseDimension
- Object
- BaseDimension
- Canon::Comparison::Dimensions::CommentsDimension
- Defined in:
- lib/canon/comparison/dimensions/comments_dimension.rb
Overview
Comments dimension
Handles comparison of comment nodes. Supports :strict and :ignore behaviors.
Behaviors:
-
:strict - Exact comment comparison including whitespace
-
:ignore - Skip comment comparison
Constant Summary
Constants inherited from BaseDimension
BaseDimension::IGNORE, BaseDimension::NORMALIZE, BaseDimension::STRICT
Instance Method Summary collapse
-
#compare_normalize(comments1, comments2) ⇒ Boolean
Normalized comment comparison.
-
#compare_strict(comments1, comments2) ⇒ Boolean
Strict comment comparison.
-
#extract_data(node) ⇒ Array<String>
Extract comments from a node.
Methods inherited from BaseDimension
#compare, #dimension_name, #equivalent?, #supports_normalization?
Instance Method Details
#compare_normalize(comments1, comments2) ⇒ Boolean
Normalized comment comparison
For comments, normalized comparison collapses whitespace in each comment.
51 52 53 |
# File 'lib/canon/comparison/dimensions/comments_dimension.rb', line 51 def compare_normalize(comments1, comments2) # rubocop:disable Naming/PredicateMethod normalize_comments(comments1) == normalize_comments(comments2) end |
#compare_strict(comments1, comments2) ⇒ Boolean
Strict comment comparison
40 41 42 |
# File 'lib/canon/comparison/dimensions/comments_dimension.rb', line 40 def compare_strict(comments1, comments2) # rubocop:disable Naming/PredicateMethod comments1 == comments2 end |
#extract_data(node) ⇒ Array<String>
Extract comments from a node
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/canon/comparison/dimensions/comments_dimension.rb', line 21 def extract_data(node) return [] unless node # Handle Moxml nodes if node.is_a?(Moxml::Node) extract_from_moxml(node) # Handle Nokogiri nodes elsif node.is_a?(Nokogiri::XML::Node) extract_from_nokogiri(node) else [] end end |