Class: Chromaprint::Fingerprint
- Inherits:
-
Object
- Object
- Chromaprint::Fingerprint
- Defined in:
- lib/chromaprint/fingerprint.rb
Overview
Contains compressed and raw fingerprints and provides a method to compare them against other fingerprints.
Constant Summary collapse
- BITS_PER_RAW_ITEM =
Number of bits in one item of raw fingerprint
32
Instance Attribute Summary collapse
- #compressed ⇒ Object readonly
- #raw ⇒ Object readonly
Instance Method Summary collapse
-
#compare(fingerprint) ⇒ Float
Compare a fingerprint against another fingerprint.
-
#initialize(compressed, raw) ⇒ Fingerprint
constructor
A new instance of Fingerprint.
Constructor Details
#initialize(compressed, raw) ⇒ Fingerprint
Returns a new instance of Fingerprint.
17 18 19 20 |
# File 'lib/chromaprint/fingerprint.rb', line 17 def initialize(compressed, raw) @compressed = compressed @raw = raw end |
Instance Attribute Details
#compressed ⇒ Object (readonly)
9 10 11 |
# File 'lib/chromaprint/fingerprint.rb', line 9 def compressed @compressed end |
#raw ⇒ Object (readonly)
13 14 15 |
# File 'lib/chromaprint/fingerprint.rb', line 13 def raw @raw end |
Instance Method Details
#compare(fingerprint) ⇒ Float
Compare a fingerprint against another fingerprint.
27 28 29 30 31 32 33 34 |
# File 'lib/chromaprint/fingerprint.rb', line 27 def compare(fingerprint) max_raw_size = [@raw.size, fingerprint.raw.size].max bit_size = max_raw_size * BITS_PER_RAW_ITEM distance = hamming_distance(@raw, fingerprint.raw) 1 - distance.to_f / bit_size end |