link_thumbnailer 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +7 -0
- data/README.md +9 -0
- data/lib/link_thumbnailer/version.rb +1 -1
- data/lib/link_thumbnailer/web_image.rb +9 -6
- data/spec/web_image_spec.rb +43 -5
- metadata +1 -1
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -64,6 +64,15 @@ Now with a regular website with no particular protocol:
|
|
64
64
|
object.images.first.source_url
|
65
65
|
=> #<URI::HTTP:0x007ff7a923ef58 URL:http://foo.com/media/BAhbB1sHOgZmSSItMjAxMi8wNC8yNi8yMC8xMS80OS80MjYvY29yZG92YWJlYWNoLmpwZwY6BkVUWwg6BnA6CnRodW1iSSINNzUweDIwMCMGOwZU/cordovabeach.jpg>
|
66
66
|
|
67
|
+
object.images.first.to_json
|
68
|
+
=> "{\"source_url\":\"http://foo.com/media/BAhbB1sHOgZmSSItMjAxMi8wNC8yNi8yMC8xMS80OS80MjYvY29yZG92YWJlYWNoLmpwZwY6BkVUWwg6BnA6CnRodW1iSSINNzUweDIwMCMGOwZU/cordovabeach.jpg\",\"mime_type\":\"image/jpeg\",\"density\":\"72x72\",\"rows\":200,\"filesize\":46501,\"number_colors\":9490}"
|
69
|
+
|
70
|
+
object.images.first.to_a
|
71
|
+
=> {:source_url=>#<URI::HTTP:0x007f8a4a2561c0 URL:http://foo.com/media/BAhbB1sHOgZmSSItMjAxMi8wNC8yNi8yMC8xMS80OS80MjYvY29yZG92YWJlYWNoLmpwZwY6BkVUWwg6BnA6CnRodW1iSSINNzUweDIwMCMGOwZU/cordovabeach.jpg>, :mime_type=>"image/jpeg", :density=>"72x72", :rows=>200, :filesize=>46501, :number_colors=>9490}
|
72
|
+
|
73
|
+
object.images.map(&:to_a)
|
74
|
+
=> [{:source_url=>#<URI::HTTP:0x007f8a4a2561c0 URL:http://foo.com/media/BAhbB1sHOgZmSSItMjAxMi8wNC8yNi8yMC8xMS80OS80MjYvY29yZG92YWJlYWNoLmpwZwY6BkVUWwg6BnA6CnRodW1iSSINNzUweDIwMCMGOwZU/cordovabeach.jpg>, :mime_type=>"image/jpeg", :density=>"72x72", :rows=>200, :filesize=>46501, :number_colors=>9490}]
|
75
|
+
|
67
76
|
You can check whether this object is valid or not (set mandatory attributes in the initializer, defaults are `[url, title, images]`)
|
68
77
|
|
69
78
|
object.valid?
|
@@ -3,16 +3,19 @@ require 'json'
|
|
3
3
|
module LinkThumbnailer
|
4
4
|
module WebImage
|
5
5
|
|
6
|
-
attr_accessor :source_url
|
7
|
-
attr_accessor :doc
|
6
|
+
attr_accessor :source_url, :doc
|
8
7
|
|
9
|
-
def
|
10
|
-
result =
|
8
|
+
def to_a
|
9
|
+
result = {}
|
11
10
|
%w(source_url mime_type density colums rows filesize number_colors).each {|m|
|
12
|
-
result
|
11
|
+
result[m.to_sym] = self.send(m) if self.respond_to?(m)
|
13
12
|
}
|
14
13
|
|
15
|
-
|
14
|
+
result
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_json
|
18
|
+
JSON(self.to_a)
|
16
19
|
end
|
17
20
|
|
18
21
|
end
|
data/spec/web_image_spec.rb
CHANGED
@@ -13,34 +13,72 @@ describe LinkThumbnailer::WebImage do
|
|
13
13
|
|
14
14
|
subject { foo }
|
15
15
|
|
16
|
+
it { should respond_to :to_a }
|
16
17
|
it { should respond_to :to_json }
|
17
18
|
it { should respond_to :source_url }
|
18
19
|
it { should respond_to :doc }
|
19
20
|
|
21
|
+
describe ".to_a" do
|
22
|
+
|
23
|
+
context "with default attributes" do
|
24
|
+
|
25
|
+
let(:attributes) { [:source_url] }
|
26
|
+
|
27
|
+
subject { foo.to_a }
|
28
|
+
|
29
|
+
it { subject.keys.should eq(attributes) }
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
context "with all attributes" do
|
34
|
+
|
35
|
+
let(:attributes) { [:source_url, :mime_type, :density, :colums, :rows, :filesize, :number_colors] }
|
36
|
+
|
37
|
+
before do
|
38
|
+
attributes.each {|a| foo.class.send(:define_method, a.to_sym) { 'foo' } }
|
39
|
+
end
|
40
|
+
|
41
|
+
after do
|
42
|
+
attributes.each {|a| foo.class.send(:undef_method, a.to_sym) }
|
43
|
+
end
|
44
|
+
|
45
|
+
subject { foo.to_a }
|
46
|
+
|
47
|
+
it { subject.keys.should eq(attributes) }
|
48
|
+
it { subject.values.should include('foo') }
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
20
54
|
describe ".to_json" do
|
21
55
|
|
22
56
|
context "with default attributes" do
|
23
57
|
|
24
|
-
let(:attributes) {
|
58
|
+
let(:attributes) { [:source_url] }
|
25
59
|
|
26
60
|
subject { foo.to_json }
|
27
61
|
|
28
|
-
it { JSON.parse(subject).
|
62
|
+
it { JSON.parse(subject).keys.map(&:to_sym).should eq(attributes) }
|
29
63
|
|
30
64
|
end
|
31
65
|
|
32
66
|
context "with all attributes" do
|
33
67
|
|
34
|
-
let(:attributes) {
|
68
|
+
let(:attributes) { [:source_url, :mime_type, :density, :colums, :rows, :filesize, :number_colors] }
|
35
69
|
|
36
70
|
before do
|
37
71
|
attributes.each {|a| foo.class.send(:define_method, a.to_sym) { 'foo' } }
|
38
72
|
end
|
39
73
|
|
74
|
+
after do
|
75
|
+
attributes.each {|a| foo.class.send(:undef_method, a.to_sym) }
|
76
|
+
end
|
77
|
+
|
40
78
|
subject { foo.to_json }
|
41
79
|
|
42
|
-
it {
|
43
|
-
it {
|
80
|
+
it { JSON.parse(subject).keys.map(&:to_sym).should eq(attributes) }
|
81
|
+
it { JSON.parse(subject).values.should include('foo') }
|
44
82
|
|
45
83
|
end
|
46
84
|
|