link_thumbnailer 3.0.3 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 42c12677181ae4f47f9809a31f3b857e90b6de3f
4
- data.tar.gz: d6e394503da26997c9c5cf67c58f0d9c2bea62ea
3
+ metadata.gz: f47134a149128a2df4c2a4e91fb3857b2f38d4be
4
+ data.tar.gz: 4dfb35562b6ecc861c2948cfc7e2bfb41c1b3705
5
5
  SHA512:
6
- metadata.gz: 6d29145f60542d6a5b7b8a8ba1fddc76587823348e78bf38830b3b6d75772c53e37bda89281a0586f2a56b1a0869df9ea964cc0f58d925e8d8ef2a3a067207d5
7
- data.tar.gz: 1980e7240d0c7fbe42a652ac7c1e29feceb90579dd3a6e46526cfb12d381c67e4ef55bcfd13a6d55a37a00f20cc8b37647fef6595e1bd18ca26f10e2ea56d52b
6
+ metadata.gz: dde01e9975a4da2c2044b5d6f203fbca53b04ce018dd1c5f70096fec040902a6fcd972d1fb054869572a37b74d6cdbc2281f6d93bb6f66328cb2388f6131df42
7
+ data.tar.gz: 03af8d1474d4443646a458902c9114677a71c5cfac8ef3b6e0c01964b474b3e4780001460a22b88050395a0019b818a8afbe2cefc42a39ad2edef2cf0a2a6931
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # 3.1.0
2
+
3
+ - Fix an issue when image sizes could not be retrieved.
4
+ - Grapers now accepts an optional parameter to customize the weigth of the grader in the probablity computation.
5
+
6
+ ```ruby
7
+ LinkThumbnailer::Graders::Position.new(description, weigth: 3)
8
+ ```
9
+
10
+ Will give a 3 times more weigth to the `Position` grader compare to other graders.
11
+ By default all graders have a weigth of `1`.
12
+
1
13
  # 3.0.3
2
14
 
3
15
  - Fix an issue when dealing with absolute urls. https://github.com/gottfrois/link_thumbnailer/issues/68
data/README.md CHANGED
@@ -129,7 +129,7 @@ LinkThumbnailer.configure do |config|
129
129
  # ->(description) { ::LinkThumbnailer::Graders::Length.new(description) },
130
130
  # ->(description) { ::LinkThumbnailer::Graders::HtmlAttribute.new(description, :class) },
131
131
  # ->(description) { ::LinkThumbnailer::Graders::HtmlAttribute.new(description, :id) },
132
- # ->(description) { ::LinkThumbnailer::Graders::Position.new(description) },
132
+ # ->(description) { ::LinkThumbnailer::Graders::Position.new(description, weight: 3) },
133
133
  # ->(description) { ::LinkThumbnailer::Graders::LinkDensity.new(description) }
134
134
  # ]
135
135
 
@@ -40,7 +40,7 @@ LinkThumbnailer.configure do |config|
40
40
  # ->(description) { ::LinkThumbnailer::Graders::Length.new(description) },
41
41
  # ->(description) { ::LinkThumbnailer::Graders::HtmlAttribute.new(description, :class) },
42
42
  # ->(description) { ::LinkThumbnailer::Graders::HtmlAttribute.new(description, :id) },
43
- # ->(description) { ::LinkThumbnailer::Graders::Position.new(description) },
43
+ # ->(description) { ::LinkThumbnailer::Graders::Position.new(description, weight: 3) },
44
44
  # ->(description) { ::LinkThumbnailer::Graders::LinkDensity.new(description) }
45
45
  # ]
46
46
 
@@ -50,7 +50,7 @@ module LinkThumbnailer
50
50
  ->(description) { ::LinkThumbnailer::Graders::Length.new(description) },
51
51
  ->(description) { ::LinkThumbnailer::Graders::HtmlAttribute.new(description, :class) },
52
52
  ->(description) { ::LinkThumbnailer::Graders::HtmlAttribute.new(description, :id) },
53
- ->(description) { ::LinkThumbnailer::Graders::Position.new(description) },
53
+ ->(description) { ::LinkThumbnailer::Graders::Position.new(description, weigth: 3) },
54
54
  ->(description) { ::LinkThumbnailer::Graders::LinkDensity.new(description) },
55
55
  ]
56
56
  @description_min_length = 50
@@ -25,7 +25,7 @@ module LinkThumbnailer
25
25
 
26
26
  graders.each do |lambda|
27
27
  instance = lambda.call(description)
28
- probability *= instance.call.to_f
28
+ probability *= instance.call.to_f ** instance.weight
29
29
  end
30
30
 
31
31
  probability
@@ -4,11 +4,12 @@ module LinkThumbnailer
4
4
  module Graders
5
5
  class Base < ::SimpleDelegator
6
6
 
7
- attr_reader :config, :description
7
+ attr_reader :config, :description, :options
8
8
 
9
- def initialize(description)
9
+ def initialize(description, options = {})
10
10
  @config = ::LinkThumbnailer.page.config
11
11
  @description = description
12
+ @options = options
12
13
 
13
14
  super(config)
14
15
  end
@@ -17,6 +18,10 @@ module LinkThumbnailer
17
18
  fail NotImplementedError
18
19
  end
19
20
 
21
+ def weight
22
+ options.fetch(:weigth, 1)
23
+ end
24
+
20
25
  private
21
26
 
22
27
  def node
@@ -3,7 +3,7 @@ module LinkThumbnailer
3
3
  class Size < ::LinkThumbnailer::ImageComparators::Base
4
4
 
5
5
  def call(other)
6
- (other.size.min ** 2) <=> (image.size.min ** 2)
6
+ (other.size.min.to_i ** 2) <=> (image.size.min.to_i ** 2)
7
7
  end
8
8
 
9
9
  end
@@ -1,3 +1,3 @@
1
1
  module LinkThumbnailer
2
- VERSION = '3.0.3'
2
+ VERSION = '3.1.0'
3
3
  end
data/spec/grader_spec.rb CHANGED
@@ -8,7 +8,8 @@ describe LinkThumbnailer::Grader do
8
8
  describe '#call' do
9
9
 
10
10
  let(:probability) { 0.5 }
11
- let(:grader) { double('grader', call: probability) }
11
+ let(:weight) { 2 }
12
+ let(:grader) { double('grader', call: probability, weight: weight) }
12
13
  let(:lambda) { ->(_) { grader } }
13
14
  let(:graders) { [lambda, lambda] }
14
15
  let(:action) { instance.call }
@@ -17,7 +18,7 @@ describe LinkThumbnailer::Grader do
17
18
  instance.stub(:graders).and_return(graders)
18
19
  end
19
20
 
20
- it { expect(action).to eq(0.5 * 0.5) }
21
+ it { expect(action).to eq((0.5 * 0.5) ** weight) }
21
22
 
22
23
  end
23
24
 
@@ -34,6 +34,23 @@ describe LinkThumbnailer::ImageComparators::Size do
34
34
 
35
35
  end
36
36
 
37
+ context 'when other image size could not be computed' do
38
+
39
+ let(:other_size) { [] }
40
+
41
+ it { expect(action).to eq(-1) }
42
+
43
+ end
44
+
45
+ context 'when self image size could not be computed' do
46
+
47
+ let(:image) { double(size: []) }
48
+ let(:other_size) { [10, 10] }
49
+
50
+ it { expect(action).to eq(1) }
51
+
52
+ end
53
+
37
54
  end
38
55
 
39
56
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: link_thumbnailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.3
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre-Louis Gottfrois
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-23 00:00:00.000000000 Z
11
+ date: 2015-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport