smeargle 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +3 -0
- data/lib/smeargle/image.rb +5 -11
- data/lib/smeargle/sketch.rb +2 -6
- data/lib/smeargle/version.rb +1 -1
- data/spec/smeargle/image_spec.rb +12 -12
- data/spec/smeargle/sketch_spec.rb +6 -6
- metadata +4 -4
data/CHANGELOG
CHANGED
data/lib/smeargle/image.rb
CHANGED
@@ -14,22 +14,18 @@ module Smeargle
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def formatted_images
|
17
|
-
formatted_images ||=
|
17
|
+
@formatted_images ||=
|
18
18
|
image_collection.reject{ |i| corrupt? i }.
|
19
19
|
map { |i| format_image_url i }
|
20
20
|
end
|
21
21
|
|
22
22
|
def detailed_images
|
23
|
-
detailed_images ||=
|
23
|
+
@detailed_images ||=
|
24
24
|
formatted_images.map { |i| image_details i }
|
25
25
|
end
|
26
26
|
|
27
27
|
def format_image_url img
|
28
|
-
|
29
|
-
self.clean_url + img
|
30
|
-
else
|
31
|
-
img
|
32
|
-
end
|
28
|
+
URI(img).relative? ? "#{clean_url}#{img}" : img
|
33
29
|
end
|
34
30
|
|
35
31
|
def image_details img
|
@@ -49,13 +45,11 @@ module Smeargle
|
|
49
45
|
images
|
50
46
|
end
|
51
47
|
|
52
|
-
def simple_images
|
53
|
-
@simple_images ||= formatted_images
|
54
|
-
end
|
55
|
-
|
56
48
|
def corrupt? img
|
57
49
|
img =~ /\;/
|
58
50
|
end
|
59
51
|
|
52
|
+
alias_method :simple_images, :formatted_images
|
53
|
+
|
60
54
|
end
|
61
55
|
end
|
data/lib/smeargle/sketch.rb
CHANGED
@@ -13,12 +13,8 @@ module Smeargle
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def safe_url
|
16
|
-
|
17
|
-
|
18
|
-
@safe_url ||= 'http://' + url
|
19
|
-
else
|
20
|
-
@safe_url ||= url
|
21
|
-
end
|
16
|
+
@safe_url ||=
|
17
|
+
!URI.parse(url).scheme ? "http://#{url}" : url
|
22
18
|
end
|
23
19
|
|
24
20
|
def response_body
|
data/lib/smeargle/version.rb
CHANGED
data/spec/smeargle/image_spec.rb
CHANGED
@@ -14,58 +14,58 @@ describe Smeargle::Image do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
describe 'images' do
|
17
|
-
it '
|
17
|
+
it 'returns an array' do
|
18
18
|
smeargle.images.should be_a Array
|
19
19
|
end
|
20
20
|
|
21
|
-
it '
|
21
|
+
it 'contains the sample image' do
|
22
22
|
smeargle.images.first[:url].should =~ /test\.png/i
|
23
23
|
end
|
24
24
|
|
25
|
-
it '
|
25
|
+
it 'contains hashes' do
|
26
26
|
smeargle.images.first.should be_a Hash
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
describe 'format_image_url' do
|
31
|
-
it '
|
31
|
+
it 'formats relative paths' do
|
32
32
|
e = smeargle.format_image_url '/test.png'
|
33
33
|
e.should == 'http://google.com/test.png'
|
34
34
|
end
|
35
35
|
|
36
|
-
it '
|
36
|
+
it 'does not format absolute paths' do
|
37
37
|
e = smeargle.format_image_url 'http://google.com/test.png'
|
38
38
|
e.should == 'http://google.com/test.png'
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
describe 'formatted images' do
|
43
|
-
it '
|
43
|
+
it 'returns an array of formatted urls' do
|
44
44
|
e = smeargle.formatted_images
|
45
45
|
e.first.should == 'http://google.com/test.png'
|
46
46
|
end
|
47
47
|
|
48
|
-
it '
|
48
|
+
it 'excludes corrupted images' do
|
49
49
|
e = smeargle.formatted_images
|
50
50
|
e.count.should == 1
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
54
|
describe 'detailed_images' do
|
55
|
-
it '
|
55
|
+
it 'returns an array of hashes' do
|
56
56
|
e = smeargle.detailed_images
|
57
57
|
e.first.should be_a Hash
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
61
|
describe 'image_collection' do
|
62
|
-
it '
|
62
|
+
it 'does not contain duplicates' do
|
63
63
|
smeargle.image_collection.count.should == 2
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
67
|
describe 'filtered_images' do
|
68
|
-
it '
|
68
|
+
it 'filters images on height' do
|
69
69
|
s = Smeargle::Sketch.new 'google.com', min_width: 20
|
70
70
|
s.stub!(:image_details).and_return(
|
71
71
|
{ url: 'test.png', height: 10, width: 10 })
|
@@ -74,14 +74,14 @@ describe Smeargle::Image do
|
|
74
74
|
end
|
75
75
|
|
76
76
|
describe 'simple_images' do
|
77
|
-
it '
|
77
|
+
it 'contains an array of urls' do
|
78
78
|
s = Smeargle::Sketch.new 'google.com'
|
79
79
|
s.simple_images.first.should =~ /test\.png/
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
83
|
describe 'corrupt?' do
|
84
|
-
it '
|
84
|
+
it 'returns true for corrupt url' do
|
85
85
|
e = smeargle.corrupt? 'http:/google.com/test;test.png'
|
86
86
|
e.should be_true
|
87
87
|
end
|
@@ -10,12 +10,12 @@ describe Smeargle::Sketch do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
describe 'new' do
|
13
|
-
it '
|
13
|
+
it 'initializes url' do
|
14
14
|
s = Smeargle::Sketch.new 'http://google.com'
|
15
15
|
s.url.should == 'http://google.com'
|
16
16
|
end
|
17
17
|
|
18
|
-
it '
|
18
|
+
it 'sets min width/height' do
|
19
19
|
s = Smeargle::Sketch.new 'http://google.com',
|
20
20
|
min_width: 200, min_height: 250
|
21
21
|
s.min_width.should == 200
|
@@ -24,11 +24,11 @@ describe Smeargle::Sketch do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
describe 'safe_url' do
|
27
|
-
it '
|
27
|
+
it 'formats the url' do
|
28
28
|
smeargle.safe_url.should == 'http://google.com'
|
29
29
|
end
|
30
30
|
|
31
|
-
it '
|
31
|
+
it 'does not format safe urls' do
|
32
32
|
s = Smeargle::Sketch.new 'http://google.com'
|
33
33
|
s.safe_url.should == 'http://google.com'
|
34
34
|
s.safe_url.should == s.url
|
@@ -36,14 +36,14 @@ describe Smeargle::Sketch do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
describe 'response' do
|
39
|
-
it '
|
39
|
+
it 'generates the correct body' do
|
40
40
|
smeargle.response_body.css('body').text.
|
41
41
|
should =~ /google/i
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
45
|
describe 'clean_url' do
|
46
|
-
it '
|
46
|
+
it 'cleans up paramaters' do
|
47
47
|
s = Smeargle::Sketch.new 'google.com/test/clean?go=now'
|
48
48
|
s.clean_url.should == 'http://google.com'
|
49
49
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smeargle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -129,7 +129,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
129
129
|
version: '0'
|
130
130
|
segments:
|
131
131
|
- 0
|
132
|
-
hash:
|
132
|
+
hash: -1948350418827169577
|
133
133
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
134
|
none: false
|
135
135
|
requirements:
|
@@ -138,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
138
|
version: '0'
|
139
139
|
segments:
|
140
140
|
- 0
|
141
|
-
hash:
|
141
|
+
hash: -1948350418827169577
|
142
142
|
requirements: []
|
143
143
|
rubyforge_project:
|
144
144
|
rubygems_version: 1.8.23
|