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



30
31
32
# File 'lib/phash.rb', line 30

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Class Method Details

.for_paths(paths, *args) ⇒ Object

Init multiple image instances



35
36
37
38
39
# File 'lib/phash.rb', line 35

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

.hash_typeObject



56
57
58
# File 'lib/phash.rb', line 56

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

Instance Method Details

#compute_phashObject



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

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

#phashObject

Cached hash of text



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

def phash
  @phash ||= compute_phash
end

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

Similarity with other phash



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

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