Class: Phashion::Image
- Inherits:
-
Object
- Object
- Phashion::Image
- Defined in:
- lib/phashion.rb
Constant Summary collapse
- DEFAULT_DUPE_THRESHOLD =
15
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Instance Method Summary collapse
-
#distance_from(other) ⇒ Object
returns: an Integer representing the hamming distance from :other.
- #duplicate?(other, opts = {}) ⇒ Boolean
- #fingerprint ⇒ Object
-
#initialize(filename) ⇒ Image
constructor
A new instance of Image.
- #mh_distance_from(other) ⇒ Object
- #mh_fingerprint ⇒ Object
Constructor Details
#initialize(filename) ⇒ Image
Returns a new instance of Image.
19 20 21 |
# File 'lib/phashion.rb', line 19 def initialize(filename) @filename = filename end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
18 19 20 |
# File 'lib/phashion.rb', line 18 def filename @filename end |
Instance Method Details
#distance_from(other) ⇒ Object
returns: an Integer representing the hamming distance from :other
24 25 26 |
# File 'lib/phashion.rb', line 24 def distance_from(other) Phashion.hamming_distance(fingerprint, other.fingerprint) end |
#duplicate?(other, opts = {}) ⇒ Boolean
32 33 34 35 36 |
# File 'lib/phashion.rb', line 32 def duplicate?(other, opts={}) threshold = opts[:threshold] || DEFAULT_DUPE_THRESHOLD distance_from(other) <= threshold end |
#fingerprint ⇒ Object
38 39 40 |
# File 'lib/phashion.rb', line 38 def fingerprint @hash ||= Phashion.image_hash_for(@filename) end |
#mh_distance_from(other) ⇒ Object
28 29 30 |
# File 'lib/phashion.rb', line 28 def mh_distance_from(other) Phashion.hamming_distance2(mh_fingerprint, other.mh_fingerprint) end |
#mh_fingerprint ⇒ Object
42 43 44 |
# File 'lib/phashion.rb', line 42 def mh_fingerprint @mh_hash ||= Phashion.mh_hash_for(@filename) end |