link_thumbnailer 0.0.5 → 0.0.6

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.
@@ -1,3 +1,10 @@
1
+ # 0.0.6
2
+
3
+ - Update readme
4
+ - Add `to_a` to WebImage class
5
+ - Refactor `to_json` for WebImage class
6
+ - Add specs corresponding
7
+
1
8
  # 0.0.5
2
9
 
3
10
  - Bug fix
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?
@@ -1,3 +1,3 @@
1
1
  module LinkThumbnailer
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -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 to_json
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 << { m.to_sym => self.send(m) } if self.respond_to?(m)
11
+ result[m.to_sym] = self.send(m) if self.respond_to?(m)
13
12
  }
14
13
 
15
- JSON(result)
14
+ result
15
+ end
16
+
17
+ def to_json
18
+ JSON(self.to_a)
16
19
  end
17
20
 
18
21
  end
@@ -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) { %w(source_url) }
58
+ let(:attributes) { [:source_url] }
25
59
 
26
60
  subject { foo.to_json }
27
61
 
28
- it { JSON.parse(subject).first.keys.should eq(attributes) }
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) { %w(source_url mime_type density colums rows filesize number_colors) }
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 { puts JSON.parse(subject).map {|e| e.keys.first }.should eq(attributes) }
43
- it { puts JSON.parse(subject).map {|e| e.values.first }.should include('foo') }
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: link_thumbnailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: