Class: Canon::Comparison::Dimensions::CommentsDimension

Inherits:
BaseDimension
  • Object
show all
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

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.

Parameters:

  • comments1 (Array<String>)

    First comments array

  • comments2 (Array<String>)

    Second comments array

Returns:

  • (Boolean)

    true if normalized comments are equal



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

Parameters:

  • comments1 (Array<String>)

    First comments array

  • comments2 (Array<String>)

    Second comments array

Returns:

  • (Boolean)

    true if comments are exactly equal



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

Parameters:

  • node (Moxml::Node, Nokogiri::XML::Node)

    Node to extract from

Returns:

  • (Array<String>)

    Array of comment strings



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