Module: Ssdeep::FuzzyComparable
- Defined in:
- lib/ssdeep.rb,
lib/russdeep.rb
Overview
The FuzzyComparable module adds mixins for doing fuzzy hash comparisons. The object extending must simply implement the ‘ssdeep’ method, which should return a string containing a fuzzy CTPH hash.
Instance Method Summary collapse
-
#fuzzy_match(other, threshold = 25) ⇒ Object
Returns true/false whether the sample matches a CTPH (fuzzy hash) with a score above a specified threshold.
-
#fuzzy_score(other) ⇒ Object
Returns a CTPH comparison score between this object and another’s fuzzy hash.
Instance Method Details
#fuzzy_match(other, threshold = 25) ⇒ Object
Returns true/false whether the sample matches a CTPH (fuzzy hash) with a score above a specified threshold
46 47 48 |
# File 'lib/ssdeep.rb', line 46 def fuzzy_match(other, threshold=25) return (fuzzy_score(other) >= [threshold, 100].min) end |
#fuzzy_score(other) ⇒ Object
Returns a CTPH comparison score between this object and another’s fuzzy hash.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ssdeep.rb', line 20 def fuzzy_score(other) other_hash= if other.is_a? String other elsif other.respond_to? :ssdeep other.ssdeep else raise(TypeError, "can't handle type for other: #{other.class}") end Ssdeep.compare(self.ssdeep, other_hash) end |