plumnailer 0.0.1 → 0.0.2
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.
- data/README.textile +0 -3
- data/VERSION +1 -1
- data/lib/plumnailer/fetcher.rb +5 -1
- data/lib/plumnailer/img_comparator.rb +9 -1
- data/lib/plumnailer/img_hostname_filter.rb +1 -0
- data/lib/plumnailer/img_parser.rb +6 -2
- data/plumnailer.gemspec +2 -2
- metadata +4 -4
data/README.textile
CHANGED
@@ -1,9 +1,6 @@
|
|
1
1
|
Compare all of the images on an HTML page and select the one that best
|
2
2
|
represents what the page is about (for use as a thumbnail for the entire page).
|
3
3
|
|
4
|
-
Project is in an early stage and for now just picks the largest image on the
|
5
|
-
page. More sophisticated scoring coming soon.
|
6
|
-
|
7
4
|
<pre>
|
8
5
|
<code>
|
9
6
|
require 'plumnailer'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/lib/plumnailer/fetcher.rb
CHANGED
@@ -5,10 +5,14 @@ module Plumnailer
|
|
5
5
|
# Fetch the contents of a url.
|
6
6
|
class Fetcher
|
7
7
|
|
8
|
+
UserAgent = 'plumnailer (http://github.com/mmb/plumnailer)'
|
9
|
+
|
8
10
|
# Fetch the contents of a url.
|
9
11
|
def fetch(url)
|
10
12
|
uri = url.is_a?(URI) ? url : URI(url)
|
11
|
-
|
13
|
+
if uri.is_a?(URI::HTTP)
|
14
|
+
open(uri, 'User-Agent' => UserAgent) { |f| f.read }
|
15
|
+
end
|
12
16
|
end
|
13
17
|
|
14
18
|
end
|
@@ -5,7 +5,15 @@ module Plumnailer
|
|
5
5
|
|
6
6
|
def <=> other
|
7
7
|
# can use doc here to take source page into account
|
8
|
-
|
8
|
+
|
9
|
+
# square of smallest dimension
|
10
|
+
result = ([other.rows, other.columns].min ** 2) <=>
|
11
|
+
([rows, columns].min ** 2)
|
12
|
+
# if still tied use number of colors
|
13
|
+
if result == 0
|
14
|
+
result = other.number_colors <=> number_colors
|
15
|
+
end
|
16
|
+
result
|
9
17
|
end
|
10
18
|
|
11
19
|
end
|
@@ -14,8 +14,12 @@ module Plumnailer
|
|
14
14
|
|
15
15
|
# Parse image data from one or more urls.
|
16
16
|
def parse(img_urls)
|
17
|
-
if img_urls.respond_to? :
|
18
|
-
|
17
|
+
if img_urls.respond_to? :inject
|
18
|
+
cache = {}
|
19
|
+
img_urls.inject([]) do |memo,u|
|
20
|
+
# nil values should be cached
|
21
|
+
memo << (cache.include?(u) ? cache[u] : (cache[u] = parse_one(u)))
|
22
|
+
end.compact
|
19
23
|
else
|
20
24
|
parse_one i
|
21
25
|
end
|
data/plumnailer.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{plumnailer}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Matthew M. Boedicker"]
|
12
|
-
s.date = %q{2010-11-
|
12
|
+
s.date = %q{2010-11-11}
|
13
13
|
s.description = %q{Choose the most representative image on an HTML page for use as a thumbnail}
|
14
14
|
s.email = %q{matthewm@boedicker.org}
|
15
15
|
s.extra_rdoc_files = [
|
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:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
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: 2010-11-
|
18
|
+
date: 2010-11-11 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|