Module: Licensure::LicenseMatcher

Defined in:
lib/licensure/license_matcher.rb

Overview

Compares license labels with lightweight normalization.

Class Method Summary collapse

Class Method Details

.fingerprint(value) ⇒ String?

Parameters:

  • value (String, nil)

Returns:

  • (String, nil)


23
24
25
26
27
28
29
30
# File 'lib/licensure/license_matcher.rb', line 23

def fingerprint(value)
  normalized = value.to_s.downcase
                    .gsub(/\b(the|license|version)\b/, "")
                    .gsub(/[^a-z0-9]/, "")
  return nil if normalized.empty?

  normalized
end

.match?(left, right) ⇒ Boolean

Parameters:

  • left (String)
  • right (String)

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
# File 'lib/licensure/license_matcher.rb', line 11

def match?(left, right)
  return true if left == right

  left_fingerprint = fingerprint(left)
  right_fingerprint = fingerprint(right)
  return false unless left_fingerprint && right_fingerprint

  left_fingerprint == right_fingerprint
end