Class: Tlsh::TlshInstance
- Inherits:
-
Object
- Object
- Tlsh::TlshInstance
- Defined in:
- lib/tlsh/tlsh_instance.rb
Overview
TlshInstance represents single TLSH instance.
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#checksum ⇒ Object
Returns the value of attribute checksum.
-
#l_value ⇒ Object
Returns the value of attribute l_value.
-
#q1_ratio ⇒ Object
Returns the value of attribute q1_ratio.
-
#q2_ratio ⇒ Object
Returns the value of attribute q2_ratio.
-
#q_ratio ⇒ Object
Returns the value of attribute q_ratio.
Instance Method Summary collapse
-
#binary ⇒ Object
Returns the binary representation of the TLSH hash.
- #comparable? ⇒ Boolean
-
#diff(other) ⇒ Object
Returns diff (or similarity) against another TlshInstance.
-
#initialize(params = {}) ⇒ TlshInstance
constructor
Creates new instance of TlshInstance from the named arguments.
-
#string ⇒ Object
Returns the string representation of the TLSH hash.
Constructor Details
#initialize(params = {}) ⇒ TlshInstance
Creates new instance of TlshInstance from the named arguments.
9 10 11 12 13 14 |
# File 'lib/tlsh/tlsh_instance.rb', line 9 def initialize(params = {}) params.each do |key, value| setter = "#{key}=" send(setter, value) if respond_to?(setter.to_sym, false) end end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
4 5 6 |
# File 'lib/tlsh/tlsh_instance.rb', line 4 def body @body end |
#checksum ⇒ Object
Returns the value of attribute checksum.
4 5 6 |
# File 'lib/tlsh/tlsh_instance.rb', line 4 def checksum @checksum end |
#l_value ⇒ Object
Returns the value of attribute l_value.
4 5 6 |
# File 'lib/tlsh/tlsh_instance.rb', line 4 def l_value @l_value end |
#q1_ratio ⇒ Object
Returns the value of attribute q1_ratio.
4 5 6 |
# File 'lib/tlsh/tlsh_instance.rb', line 4 def q1_ratio @q1_ratio end |
#q2_ratio ⇒ Object
Returns the value of attribute q2_ratio.
4 5 6 |
# File 'lib/tlsh/tlsh_instance.rb', line 4 def q2_ratio @q2_ratio end |
#q_ratio ⇒ Object
Returns the value of attribute q_ratio.
4 5 6 |
# File 'lib/tlsh/tlsh_instance.rb', line 4 def q_ratio @q_ratio end |
Instance Method Details
#binary ⇒ Object
Returns the binary representation of the TLSH hash.
It’s constructed as a concatenation of hash metadata and body,
30 31 32 |
# File 'lib/tlsh/tlsh_instance.rb', line 30 def binary [swap_byte(checksum), swap_byte(l_value), q_ratio] + body end |
#comparable? ⇒ Boolean
43 44 45 |
# File 'lib/tlsh/tlsh_instance.rb', line 43 def comparable? checksum && l_value && q1_ratio && q2_ratio && q_ratio && body end |
#diff(other) ⇒ Object
Returns diff (or similarity) against another TlshInstance.
The closer to 0, the smaller the diff. Both instances have to be comparable for comparison. If not, -1 is returned.
21 22 23 |
# File 'lib/tlsh/tlsh_instance.rb', line 21 def diff(other) Distance.diff_total(self, other, true) end |
#string ⇒ Object
Returns the string representation of the TLSH hash.
It’s constructed from the binary representation of the hash, converted to hex
39 40 41 |
# File 'lib/tlsh/tlsh_instance.rb', line 39 def string binary.map { |i| i.to_i.to_s(16) }.join('') end |