pHash 1.1.5 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- N2NlYjQ5MmIzODI3NmNmN2JjODUzZjE3NTcyYTYyMGM5M2NlODI0Mg==
4
+ MWZmNjAyM2VhNWJlZDZmMWEyYTVjZmJlNzYzZTkwNDMyNzFmOGNmNA==
5
5
  data.tar.gz: !binary |-
6
- ZGYzMzkwODk2YTFiZDE4YTY5NDhiNjhkMDkyYzhlNTdhMjhlMWYxYw==
7
- !binary "U0hBNTEy":
6
+ MWI5MWY0YWViNDM5MjM2ODYzMDU1MGNlZjBmNTE2YTY1MjE1MjI2MA==
7
+ SHA512:
8
8
  metadata.gz: !binary |-
9
- YjViZjJmNmE5NGViMTE3MDAzNzVmODdlZGExNTg3MGZhZDFkMTA5NTBmYTI3
10
- N2I2NjQ3OTk2M2Y4NGEzNGUxYzU5NzYxYWNlZTIwZjI3ODU0MjgzOTQ2NTVm
11
- OThlZWUxMDNkNjFiMjBiODZmNjIyODIzY2JmMTIzYTI5YTAyNDY=
9
+ YzliZDhmNzk2NDhiZjQzNDBkOTZhMWNlYzdmMTk1ODViYWRiYjZjNDc5MTcy
10
+ NGQ5OGNiNDkxMjEyNGYyYmUxZjJkNDg5MjFiM2ZlZTkxNmYxOWUwMjc4M2Nk
11
+ MTYwNGZiYjM2ODBkNDY3ZTA5NWI0ZmMwNDA0NTczYjRkZTVjZDM=
12
12
  data.tar.gz: !binary |-
13
- Y2MxZGE1MDhlMWY0MjQwMTIzZDVlNDBlMDllNmU3OTY0NzY5NmY0YWE3OTUw
14
- YWI5ZmU3MWFhZTI1MmJkZmQ2NjUyMDZlZWQ2NzQ0MTM0MGZhMmRlZjk0ZWE1
15
- ZmE2MDFiNWNiYTIyOTM2OTkxNTkzZWM4OGY4NDkxNDIzYzFiNzI=
13
+ ZmY4ZGU1OWUyZDUzN2RhNGEwODU5YzhkYjA1ZDAyYjIyOTkxMmVkYzU1NjU3
14
+ YzJiNTk3Y2I0ZjZlODk0YzY5Y2I5YTE5NDAzOWJmMWE4ZTdjNzE2MWEwNGIy
15
+ MWY2ZjMyN2JlY2EzNTY4YWU3MDEwNThiZjFiNzkwZTcyOTQ0M2I=
@@ -61,6 +61,6 @@ Texts:
61
61
 
62
62
  ## Copyright
63
63
 
64
- Copyright (c) 2011-2014 Ivan Kuchin.
64
+ Copyright (c) 2011-2017 Ivan Kuchin.
65
65
  Released under the GPLv3 as required by license of underlying pHash library.
66
66
  See LICENSE.txt for details.
@@ -7,6 +7,10 @@ module Phash
7
7
  @data = data
8
8
  @length = length if length
9
9
  end
10
+
11
+ def inspect
12
+ "#<#{self.class.name} #{to_s}>"
13
+ end
10
14
  end
11
15
 
12
16
  class HashData < Data
@@ -1,3 +1,4 @@
1
- %w[audio image text video].each do |type|
2
- require "phash/#{type}"
3
- end
1
+ require 'phash/audio'
2
+ require 'phash/image'
3
+ require 'phash/text'
4
+ require 'phash/video'
@@ -111,6 +111,11 @@ module Phash
111
111
 
112
112
  # Class to store audio hash and compare to other
113
113
  class AudioHash < HashData
114
+ private
115
+
116
+ def to_s
117
+ data.read_array_of_type(:uint32, :read_uint32, length).map{ |n| format('%08x', n) }.join(' ')
118
+ end
114
119
  end
115
120
 
116
121
  # Class to store audio file hash and compare to other
@@ -45,6 +45,11 @@ module Phash
45
45
 
46
46
  # Class to store image hash and compare to other
47
47
  class ImageHash < HashData
48
+ private
49
+
50
+ def to_s
51
+ format('%016x', data)
52
+ end
48
53
  end
49
54
 
50
55
  # Class to store image file hash and compare to other
@@ -83,6 +83,14 @@ module Phash
83
83
 
84
84
  # Class to store text hash and compare to other
85
85
  class TextHash < HashData
86
+ private
87
+
88
+ def to_s
89
+ length.times.map do |i|
90
+ p = TxtHashPoint.new(data + TxtHashPoint.size * i)
91
+ format('%016x(%i)', p[:hash], p[:index])
92
+ end.join(' ')
93
+ end
86
94
  end
87
95
 
88
96
  # Class to store text file hash and compare to other
@@ -39,6 +39,11 @@ module Phash
39
39
 
40
40
  # Class to store video hash and compare to other
41
41
  class VideoHash < HashData
42
+ private
43
+
44
+ def to_s
45
+ data.read_array_of_type(:uint64, :read_uint64, length).map{ |n| format('%016x', n) }.join(' ')
46
+ end
42
47
  end
43
48
 
44
49
  # Class to store video file hash and compare to other
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'pHash'
5
- s.version = '1.1.5'
5
+ s.version = '1.2.0'
6
6
  s.summary = %q{Use pHash with ruby}
7
7
  s.homepage = "http://github.com/toy/#{s.name}"
8
8
  s.authors = ['Ivan Kuchin']
@@ -17,6 +17,11 @@ Gem::Specification.new do |s|
17
17
 
18
18
  s.add_dependency 'ffi', '~> 1.0'
19
19
 
20
- s.add_development_dependency 'bundler'
21
- s.add_development_dependency 'rspec'
20
+ s.add_development_dependency 'rspec', '~> 3.0'
21
+
22
+ if Gem::Platform.local.os == 'darwin'
23
+ s.post_install_message = "pHash library can be installed using macports or brew:
24
+ \tport install pHash
25
+ \tbrew install --without-video-hash homebrew/boneyard/phash"
26
+ end
22
27
  end
@@ -1,43 +1,30 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
1
+ require 'phash'
2
2
 
3
- describe :Phash do
4
- include SpecHelpers
3
+ {
4
+ Phash::Audio => '*.mp3',
5
+ Phash::Image => '**/*.{jpg,png}',
6
+ Phash::Text => '*.txt',
7
+ Phash::Video => '*.mp4',
8
+ }.each do |klass, glob|
9
+ describe klass do
10
+ filenames = Dir.glob(File.join(File.dirname(__FILE__), 'data', glob))
5
11
 
6
- shared_examples :similarity do
7
- it "should return valid similarities" do
8
- collection.combination(2) do |a, b|
9
- if main_name(a.path) == main_name(b.path)
10
- (a % b).should > 0.8
11
- else
12
- (a % b).should <= 0.5
12
+ klass.for_paths(filenames).combination(2) do |a, b|
13
+ similar = a.path.split('-')[0] == b.path.split('-')[0]
14
+
15
+ if similar
16
+ it "finds #{a.path} and #{b.path} similar" do
17
+ expect(a % b).to be > 0.8
18
+ end
19
+ else
20
+ it "finds #{a.path} and #{b.path} not similar" do
21
+ expect(a % b).to be <= 0.5
13
22
  end
14
23
  end
15
- end
16
24
 
17
- it "should return same similarity if swapping instances" do
18
- collection.combination(2) do |a, b|
19
- (a % b).should == (b % a)
25
+ it 'returns same result when switching arguments' do
26
+ expect(a % b).to eq(b % a)
20
27
  end
21
28
  end
22
29
  end
23
-
24
- describe :Audio do
25
- let(:collection){ Phash::Audio.for_paths filenames('*.mp3') }
26
- include_examples :similarity
27
- end
28
-
29
- describe :Image do
30
- let(:collection){ Phash::Image.for_paths filenames('**/*.{jpg,png}') }
31
- include_examples :similarity
32
- end
33
-
34
- describe :Text do
35
- let(:collection){ Phash::Text.for_paths filenames('*.txt') }
36
- include_examples :similarity
37
- end
38
-
39
- # describe :Video do
40
- # let(:collection){ Phash::Video.for_paths filenames('*.mp4') }
41
- # include_examples :similarity
42
- # end
43
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pHash
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Kuchin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-23 00:00:00.000000000 Z
11
+ date: 2017-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -24,34 +24,20 @@ dependencies:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.0'
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ! '>='
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ! '>='
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rspec
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
- - - ! '>='
31
+ - - ~>
46
32
  - !ruby/object:Gem::Version
47
- version: '0'
33
+ version: '3.0'
48
34
  type: :development
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
- - - ! '>='
38
+ - - ~>
53
39
  - !ruby/object:Gem::Version
54
- version: '0'
40
+ version: '3.0'
55
41
  description:
56
42
  email:
57
43
  executables: []
@@ -110,12 +96,12 @@ files:
110
96
  - spec/data/vader-m.mp3
111
97
  - spec/data/vader-o.mp3
112
98
  - spec/phash_spec.rb
113
- - spec/spec_helper.rb
114
99
  homepage: http://github.com/toy/pHash
115
100
  licenses:
116
101
  - GPLv3
117
102
  metadata: {}
118
- post_install_message:
103
+ post_install_message: ! "pHash library can be installed using macports or brew:\n\tport
104
+ install pHash\n\tbrew install --without-video-hash homebrew/boneyard/phash"
119
105
  rdoc_options: []
120
106
  require_paths:
121
107
  - lib
@@ -131,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
117
  version: '0'
132
118
  requirements: []
133
119
  rubyforge_project: pHash
134
- rubygems_version: 2.0.3
120
+ rubygems_version: 2.6.4
135
121
  signing_key:
136
122
  specification_version: 4
137
123
  summary: Use pHash with ruby
@@ -177,5 +163,4 @@ test_files:
177
163
  - spec/data/vader-m.mp3
178
164
  - spec/data/vader-o.mp3
179
165
  - spec/phash_spec.rb
180
- - spec/spec_helper.rb
181
166
  has_rdoc:
@@ -1,14 +0,0 @@
1
- $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
2
- require 'rspec'
3
- require 'phash'
4
-
5
- module SpecHelpers
6
- def filenames(pattern)
7
- data_dir = File.join File.dirname(__FILE__), 'data'
8
- Dir.glob(File.join data_dir, pattern)
9
- end
10
-
11
- def main_name(path)
12
- File.basename(path).split('-', 2).first
13
- end
14
- end