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



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

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Class Method Details

.for_paths(paths, *args) ⇒ Object

Init multiple image instances



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

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

.hash_typeObject



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

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

Instance Method Details

#compute_phashObject



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

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

#phashObject

Cached hash of text



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

def phash
  @phash ||= compute_phash
end

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

Similarity with other phash



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

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