plumnailer 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -1,19 +1,46 @@
1
- Compare all of the images on an HTML page and select the one that best
2
- represents what the page is about (for use as a thumbnail for the entire page).
1
+ Compare all of the images on an HTML page and sort them according to how well
2
+ they represent what the page is about. The top image could be used as a
3
+ thumbnail to represent the entire page.
4
+
5
+ Basic usage:
6
+
7
+ <pre>
8
+ <code>
9
+ require 'plumnailer'
10
+
11
+ chooser = Plumnailer::Chooser.new
12
+ choice = chooser.choose('http://urls.matthewm.boedicker.org/')
13
+ puts choice.source_url
14
+
15
+ choice.resize_to_fill(64, 64).write('thumb.jpg')
16
+ </code>
17
+ </pre>
18
+
19
+ Alternate fetcher that caches images on local filesystem:
3
20
 
4
21
  <pre>
5
22
  <code>
6
23
  require 'plumnailer'
7
24
 
8
25
  chooser = Plumnailer::Chooser.new
9
- # caching fetcher is good for testing
10
26
  chooser.fetcher = chooser.img_parser.fetcher =
11
27
  Plumnailer::CachingFetcher.new('/tmp/plumnailer-test')
12
28
 
13
29
  choice = chooser.choose('http://urls.matthewm.boedicker.org/')
14
30
  puts choice.source_url
31
+ </code>
32
+ </pre>
15
33
 
16
- choice.resize_to_fill(64, 64).write('thumb.jpg')
34
+ Top five images:
35
+
36
+ <pre>
37
+ <code>
38
+ require 'plumnailer'
39
+
40
+ chooser = Plumnailer::Chooser.new
41
+ chooser.choose('http://urls.matthewm.boedicker.org/', :top => 5).each do |i|
42
+ puts i.source_url
43
+ end
17
44
  </code>
18
45
  </pre>
19
46
 
@@ -12,7 +12,12 @@ module Plumnailer
12
12
  end
13
13
 
14
14
  # Find the most representative image on a page.
15
- def choose(url)
15
+ #
16
+ # Return the best image or nil if no suitable images are found.
17
+ #
18
+ # If options[:top] is passed in return up to the top n images. If this
19
+ # option is used the the method will always return of list of size 0 to n.
20
+ def choose(url, options={})
16
21
  doc_string = fetcher.fetch(url)
17
22
 
18
23
  doc = doc_parser.parse(doc_string, url)
@@ -24,14 +29,15 @@ module Plumnailer
24
29
 
25
30
  imgs = img_parser.parse(img_abs_urls)
26
31
 
27
- unless imgs.empty?
28
- imgs.each do |img|
29
- # set source document on image so it can be used in comparator
30
- img.doc = doc
31
- img.extend @img_comparator
32
- end
33
- imgs.sort.first
32
+ imgs.each do |img|
33
+ # set source document on image so it can be used in comparator
34
+ img.doc = doc
35
+ img.extend @img_comparator
34
36
  end
37
+
38
+ imgs.sort!
39
+
40
+ options[:top] ? imgs.first(options[:top]) : imgs.first
35
41
  end
36
42
 
37
43
  attr_accessor :fetcher
data/plumnailer.gemspec CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'plumnailer'
5
- s.version = '0.1.3'
6
- s.summary = 'Choose the most representative image on an HTML page for use as a thumbnail'
5
+ s.version = '0.1.4'
6
+ s.summary = 'Rank images on an HTML page for use as a thumbnail'
7
7
  s.description = s.summary
8
8
  s.homepage = 'https://github.com/mmb/plumnailer'
9
9
  s.authors = ['Matthew M. Boedicker']
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plumnailer
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 3
10
- version: 0.1.3
9
+ - 4
10
+ version: 0.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matthew M. Boedicker
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-16 00:00:00 -05:00
18
+ date: 2011-08-04 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -74,7 +74,7 @@ dependencies:
74
74
  version: "0"
75
75
  type: :development
76
76
  version_requirements: *id004
77
- description: Choose the most representative image on an HTML page for use as a thumbnail
77
+ description: Rank images on an HTML page for use as a thumbnail
78
78
  email:
79
79
  - matthewm@boedicker.org
80
80
  executables: []
@@ -132,6 +132,6 @@ rubyforge_project:
132
132
  rubygems_version: 1.5.2
133
133
  signing_key:
134
134
  specification_version: 3
135
- summary: Choose the most representative image on an HTML page for use as a thumbnail
135
+ summary: Rank images on an HTML page for use as a thumbnail
136
136
  test_files: []
137
137