class AverageHash::Image
Constants
- DEFAULT_DUPE_THRESHOLD
Attributes
file_path[R]
Public Class Methods
new(file_path)
click to toggle source
# File lib/average_hash/image.rb, line 9 def initialize(file_path) @file_path = file_path end
Public Instance Methods
distance_from(other)
click to toggle source
# File lib/average_hash/image.rb, line 18 def distance_from(other) (fingerprint ^ other.fingerprint).to_s(2).count('1') end
duplicate?(other, opts = {})
click to toggle source
# File lib/average_hash/image.rb, line 22 def duplicate?(other, opts = {}) threshold = opts[:threshold] || DEFAULT_DUPE_THRESHOLD distance_from(other) <= threshold end
fingerprint()
click to toggle source
# File lib/average_hash/image.rb, line 13 def fingerprint @average_hash ||= HashingStrategy.new(@file_path).generate_hash @average_hash.to_i(2) end