Class: AverageHash::Image
- Inherits:
-
Object
- Object
- AverageHash::Image
- Defined in:
- lib/average_hash/image.rb
Constant Summary collapse
- DEFAULT_DUPE_THRESHOLD =
5
Instance Attribute Summary collapse
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
Instance Method Summary collapse
- #distance_from(other) ⇒ Object
- #duplicate?(other, opts = {}) ⇒ Boolean
- #fingerprint ⇒ Object
-
#initialize(file_path) ⇒ Image
constructor
A new instance of Image.
Constructor Details
#initialize(file_path) ⇒ Image
Returns a new instance of Image.
9 10 11 |
# File 'lib/average_hash/image.rb', line 9 def initialize(file_path) @file_path = file_path end |
Instance Attribute Details
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
7 8 9 |
# File 'lib/average_hash/image.rb', line 7 def file_path @file_path end |
Instance Method Details
#distance_from(other) ⇒ Object
18 19 20 |
# File 'lib/average_hash/image.rb', line 18 def distance_from(other) (fingerprint ^ other.fingerprint).to_s(2).count('1') end |
#duplicate?(other, opts = {}) ⇒ Boolean
22 23 24 25 |
# File 'lib/average_hash/image.rb', line 22 def duplicate?(other, opts = {}) threshold = opts[:threshold] || DEFAULT_DUPE_THRESHOLD distance_from(other) <= threshold end |
#fingerprint ⇒ Object
13 14 15 16 |
# File 'lib/average_hash/image.rb', line 13 def fingerprint @average_hash ||= HashingStrategy.new(@file_path).generate_hash @average_hash.to_i(2) end |