Class: Phashion::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/phashion.rb

Constant Summary collapse

DEFAULT_DUPE_THRESHOLD =
15

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#filenameObject (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

Returns:

  • (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

#fingerprintObject



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_fingerprintObject



42
43
44
# File 'lib/phashion.rb', line 42

def mh_fingerprint
  @mh_hash ||= Phashion.mh_hash_for(@filename)
end