lib/abide_dev_utils/xccdf/parser/objects/digest_object.rb
# Compares two objects by their SHA256 digests
# and returns the degree to which they are similar
# as a percentage.
Compares two objects by their SHA256 digests
and returns the degree to which they are similar
as a percentage.
Compares two objects by their SHA256 digests and returns the degree to which they are similar as a percentage .
def digest_similarity(other, only_labels: [], label_weights: {})
            digest_parts = sorted_digest_parts(digest)
            number_compared = 0
            cumulative_similarity = 0.0
            digest_parts.each do |digest_part|
              label, self_digest = split_labeled_digest(digest_part)
              next unless only_labels.empty? || only_labels.include?(label)
              label_weight = label_weights.key?(label) ? label_weights[label] : 1.0
              sorted_digest_parts(other.digest).each do |other_digest_part|
                other_label, other_digest = split_labeled_digest(other_digest_part)
                next unless (label == other_label) && (self_digest == other_digest)
                number_compared += 1
                cumulative_similarity += 1.0 * label_weight
                break 
              end
            end
            cumulative_similarity / (number_compared.zero? ? 1.0 : number_compared)
          end
def digest_similarity ( other , only_labels : [ ] , label_weights : { } ) digest_parts = sorted_digest_parts ( digest ) number_compared = 0 cumulative_similarity = 0.0 digest_parts . each do | digest_part | label , self_digest = split_labeled_digest ( digest_part ) next unless only_labels . empty? || only_labels . include? ( label ) label_weight = label_weights . key? ( label ) ? label_weights [ label ] : 1.0 sorted_digest_parts ( other . digest ) . each do | other_digest_part | other_label , other_digest = split_labeled_digest ( other_digest_part ) next unless ( label == other_label ) && ( self_digest == other_digest ) number_compared += 1 cumulative_similarity += 1.0 * label_weight break end end cumulative_similarity / ( number_compared . zero? ? 1.0 : number_compared ) end
Compares two objects by their SHA256 digests
and returns the degree to which they are similar
as a percentage.
Compares two objects by their SHA256 digests and returns the degree to which they are similar as a percentage .
# break when found
other
only_labels
label_weights