Class: Phash::FileHash

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

Direct Known Subclasses

Audio, Image, Text, Video

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ FileHash

File path


26
27
28
# File 'lib/phash.rb', line 26

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path


23
24
25
# File 'lib/phash.rb', line 23

def path
  @path
end

Class Method Details

.for_paths(paths, *args) ⇒ Object

Init multiple image instances


31
32
33
34
35
# File 'lib/phash.rb', line 31

def self.for_paths(paths, *args)
  paths.map do |path|
    new(path, *args)
  end
end

.hash_typeObject


52
53
54
# File 'lib/phash.rb', line 52

def self.hash_type
  @hash_type ||= self.name.split('::').last.downcase
end

Instance Method Details

#compute_phashObject


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

def compute_phash
  Phash.send("#{self.class.hash_type}_hash", @path)
end

#phashObject

Cached hash of text


38
39
40
# File 'lib/phash.rb', line 38

def phash
  @phash ||= compute_phash
end

#similarity(other, *args) ⇒ Object Also known as: %

Similarity with other phash


47
48
49
# File 'lib/phash.rb', line 47

def similarity(other, *args)
  phash.similarity(other.phash, *args)
end