fetcher-microdata 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/fetcher-microdata/article_small.rb +1 -0
- data/lib/fetcher-microdata/user_comments.rb +22 -0
- data/lib/fetcher-microdata/version.rb +1 -1
- data/lib/fetcher-microdata.rb +3 -1
- data/lib/writer/fetcher-microdata/article_small.rb +8 -1
- data/lib/writer/fetcher-microdata/user_comments.rb +43 -0
- data/spec/fetcher/microdata/article_small_spec.rb +5 -0
- data/spec/fetcher/microdata/user_comments_spec.rb +55 -0
- data/spec/writer/fetcher/microdata/article_small_spec.rb +49 -25
- data/spec/writer/fetcher/microdata/user_comments_spec.rb +117 -0
- metadata +8 -2
@@ -0,0 +1,22 @@
|
|
1
|
+
module Fetcher
|
2
|
+
class Microdata
|
3
|
+
class UserComments < Fetcher::Microdata
|
4
|
+
|
5
|
+
def initialize *args
|
6
|
+
if args.length == 2
|
7
|
+
super *args
|
8
|
+
else
|
9
|
+
raise ArgumentError, "Wrong number of arguments #{args.length} and 2 needed"
|
10
|
+
end
|
11
|
+
@_type = 'http://schema.org/UserComments'
|
12
|
+
end
|
13
|
+
|
14
|
+
attribute :additionalType
|
15
|
+
attribute :id
|
16
|
+
attribute :commentText
|
17
|
+
attribute :creator
|
18
|
+
attribute :commentTime
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/fetcher-microdata.rb
CHANGED
@@ -40,7 +40,9 @@ require 'fetcher-microdata/version'
|
|
40
40
|
require 'fetcher-microdata/person_user'
|
41
41
|
require 'fetcher-microdata/article_small'
|
42
42
|
require 'fetcher-microdata/review'
|
43
|
+
require 'fetcher-microdata/user_comments'
|
43
44
|
|
44
45
|
require 'writer/fetcher-microdata/person_user'
|
45
46
|
require 'writer/fetcher-microdata/article_small'
|
46
|
-
require 'writer/fetcher-microdata/review'
|
47
|
+
require 'writer/fetcher-microdata/review'
|
48
|
+
require 'writer/fetcher-microdata/user_comments'
|
@@ -10,7 +10,7 @@ module Writer
|
|
10
10
|
|
11
11
|
def hash
|
12
12
|
@attributes = @source.attributes
|
13
|
-
{
|
13
|
+
resp = {
|
14
14
|
"type" => [@source._type],
|
15
15
|
"properties" => {
|
16
16
|
"additionalType" => [
|
@@ -28,6 +28,8 @@ module Writer
|
|
28
28
|
"Item#viewer" => [
|
29
29
|
@attributes[:viewer].to.hash
|
30
30
|
],
|
31
|
+
"UserComments" => [
|
32
|
+
],
|
31
33
|
"dateCreated" => [
|
32
34
|
@attributes[:dateCreated]
|
33
35
|
],
|
@@ -37,6 +39,11 @@ module Writer
|
|
37
39
|
]
|
38
40
|
}
|
39
41
|
}
|
42
|
+
@attributes[:comments].each do |c|
|
43
|
+
resp["properties"]["UserComments"].push c.to.hash
|
44
|
+
end
|
45
|
+
resp
|
46
|
+
|
40
47
|
end
|
41
48
|
end
|
42
49
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Writer
|
2
|
+
module Fetcher
|
3
|
+
module Microdata
|
4
|
+
class UserComments
|
5
|
+
attr_accessor :source
|
6
|
+
|
7
|
+
def initialize the_source
|
8
|
+
self.source = the_source
|
9
|
+
end
|
10
|
+
|
11
|
+
def hash
|
12
|
+
@attributes = @source.attributes
|
13
|
+
aux = @attributes[:id].split("_")
|
14
|
+
url = "https://www.facebook.com/#{aux[1]}?comment_id=#{aux[2]}"
|
15
|
+
{
|
16
|
+
"type" => [@source._type],
|
17
|
+
"properties" => {
|
18
|
+
"additionalType" => [
|
19
|
+
@attributes[:additionalType]
|
20
|
+
],
|
21
|
+
"Item#id" => [
|
22
|
+
"#{@attributes[:id]}"
|
23
|
+
],
|
24
|
+
"commentText" => [
|
25
|
+
@attributes[:commentText]
|
26
|
+
],
|
27
|
+
"creator" => [
|
28
|
+
@attributes[:creator].to.hash
|
29
|
+
],
|
30
|
+
"commentTime" => [
|
31
|
+
@attributes[:commentTime]
|
32
|
+
],
|
33
|
+
"url" => [
|
34
|
+
url
|
35
|
+
]
|
36
|
+
}
|
37
|
+
|
38
|
+
}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -42,6 +42,11 @@ describe Fetcher::Microdata::ArticleSmall do
|
|
42
42
|
.attributes.should have_key :articleBody
|
43
43
|
end
|
44
44
|
|
45
|
+
it 'should set attribute comments' do
|
46
|
+
Fetcher::Microdata::ArticleSmall.new(@arg1, @arg2, @arg3)
|
47
|
+
.attributes.should have_key :comments
|
48
|
+
end
|
49
|
+
|
45
50
|
it 'should set attribute author' do
|
46
51
|
Fetcher::Microdata::ArticleSmall.new(@arg1, @arg2, @arg3)
|
47
52
|
.attributes.should have_key :author
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Fetcher::Microdata::UserComments do
|
4
|
+
describe '.new' do
|
5
|
+
it 'should set the _type to schema.org/UserComments' do
|
6
|
+
@arg = stub "arg"
|
7
|
+
article = Fetcher::Microdata::UserComments.new @arg, @argument
|
8
|
+
article._type.should == "http://schema.org/UserComments"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should raise wrong number of argument if the count of arguments is distinct of 2' do
|
13
|
+
expect {
|
14
|
+
Fetcher::Microdata::UserComments.new "a", "b", "c", "d"
|
15
|
+
}.to raise_error
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should inherit from Fetcher::Microdata' do
|
19
|
+
Fetcher::Microdata::UserComments.superclass.should == Fetcher::Microdata
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'attributes' do
|
23
|
+
before do
|
24
|
+
@arg1 = stub "args1"
|
25
|
+
@arg2 = stub "args2"
|
26
|
+
Fetcher::Microdata::UserComments.any_instance.stub :coerce
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should set attribute additionalType' do
|
30
|
+
Fetcher::Microdata::UserComments.new(@arg1, @arg2)
|
31
|
+
.attributes.should have_key :additionalType
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should set attribute id' do
|
35
|
+
Fetcher::Microdata::UserComments.new(@arg1, @arg2)
|
36
|
+
.attributes.should have_key :id
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should set attribute commentText' do
|
40
|
+
Fetcher::Microdata::UserComments.new(@arg1, @arg2)
|
41
|
+
.attributes.should have_key :commentText
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should set attribute creator' do
|
45
|
+
Fetcher::Microdata::UserComments.new(@arg1, @arg2)
|
46
|
+
.attributes.should have_key :creator
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should set attribute commentTime' do
|
50
|
+
Fetcher::Microdata::UserComments.new(@arg1, @arg2)
|
51
|
+
.attributes.should have_key :commentTime
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
@@ -6,6 +6,33 @@ describe Writer::Fetcher::Microdata::ArticleSmall do
|
|
6
6
|
@schema_stub = stub 'schema'
|
7
7
|
@author_stub = stub 'author', :to => stub( :hash => nil)
|
8
8
|
@viewer_stub = stub 'viewer', :to => stub( :hash => nil)
|
9
|
+
@attr_stub = stub 'attr stub'
|
10
|
+
stub1 = stub 'coment1', :to => "hola1"
|
11
|
+
stub2 = stub 'coment2', :to => "hola2"
|
12
|
+
|
13
|
+
@attr_stub.stub(:[]) do |simbol|
|
14
|
+
if simbol == :author
|
15
|
+
@author_stub
|
16
|
+
elsif simbol == :viewer
|
17
|
+
@viewer_stub
|
18
|
+
elsif simbol == :comments
|
19
|
+
[stub1,stub2]
|
20
|
+
elsif simbol == :additionalType
|
21
|
+
"http://getfetcher.net/Item"
|
22
|
+
elsif simbol == :id
|
23
|
+
234536234
|
24
|
+
elsif simbol == :articleBody
|
25
|
+
"some body"
|
26
|
+
elsif simbol == :dateCreated
|
27
|
+
23456235
|
28
|
+
elsif simbol == :provider
|
29
|
+
["twitter", "fetcher"]
|
30
|
+
elsif simbol == :url
|
31
|
+
"http://myurl.info"
|
32
|
+
else
|
33
|
+
stub('the hash', :[] => @attr_stub)
|
34
|
+
end
|
35
|
+
end
|
9
36
|
end
|
10
37
|
|
11
38
|
it 'should return a hash with the type' do
|
@@ -15,7 +42,7 @@ describe Writer::Fetcher::Microdata::ArticleSmall do
|
|
15
42
|
]
|
16
43
|
}
|
17
44
|
@schema_stub.should_receive(:_type).and_return "the type"
|
18
|
-
@schema_stub.should_receive(:attributes).and_return
|
45
|
+
@schema_stub.should_receive(:attributes).and_return @attr_stub
|
19
46
|
|
20
47
|
writer = Writer::Fetcher::Microdata::ArticleSmall.new @schema_stub
|
21
48
|
writer.hash.should include final_hash
|
@@ -32,10 +59,7 @@ describe Writer::Fetcher::Microdata::ArticleSmall do
|
|
32
59
|
"http://getfetcher.net/Item"
|
33
60
|
]
|
34
61
|
}
|
35
|
-
@schema_stub.should_receive(:attributes)
|
36
|
-
.and_return :additionalType => "http://getfetcher.net/Item",
|
37
|
-
:author => @author_stub,
|
38
|
-
:viewer => @viewer_stub
|
62
|
+
@schema_stub.should_receive(:attributes).and_return @attr_stub
|
39
63
|
end
|
40
64
|
|
41
65
|
it 'should include the Item#id' do
|
@@ -44,9 +68,19 @@ describe Writer::Fetcher::Microdata::ArticleSmall do
|
|
44
68
|
234536234
|
45
69
|
]
|
46
70
|
}
|
71
|
+
@schema_stub.should_receive(:attributes).and_return @attr_stub
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should include the UserComments' do
|
75
|
+
a = "hola1".hash
|
76
|
+
b = "hola2".hash
|
77
|
+
@properties_hash = {
|
78
|
+
"UserComments" => [
|
79
|
+
a,b
|
80
|
+
]
|
81
|
+
}
|
47
82
|
|
48
|
-
@schema_stub.should_receive(:attributes)
|
49
|
-
.and_return :id => 234536234, :author => @author_stub, :viewer => @viewer_stub
|
83
|
+
@schema_stub.should_receive(:attributes).and_return @attr_stub
|
50
84
|
end
|
51
85
|
|
52
86
|
it 'should include the articleBody' do
|
@@ -55,39 +89,33 @@ describe Writer::Fetcher::Microdata::ArticleSmall do
|
|
55
89
|
"some body"
|
56
90
|
]
|
57
91
|
}
|
58
|
-
|
59
|
-
@schema_stub.should_receive(:attributes)
|
60
|
-
.and_return :articleBody => "some body", :author => @author_stub, :viewer => @viewer_stub
|
92
|
+
@schema_stub.should_receive(:attributes).and_return @attr_stub
|
61
93
|
end
|
62
94
|
|
63
95
|
it 'should include the author' do
|
64
|
-
@author = stub 'author'
|
65
96
|
@author_writer = stub 'author writer'
|
66
97
|
@author_writer.should_receive(:hash).and_return "hi Im the author"
|
67
|
-
@
|
98
|
+
@author_stub.should_receive(:to).and_return @author_writer
|
68
99
|
@properties_hash = {
|
69
100
|
"author" => [
|
70
101
|
"hi Im the author"
|
71
102
|
]
|
72
103
|
}
|
73
104
|
|
74
|
-
@schema_stub.should_receive(:attributes)
|
75
|
-
.and_return :author => @author, :viewer => @viewer_stub
|
105
|
+
@schema_stub.should_receive(:attributes).and_return @attr_stub
|
76
106
|
end
|
77
107
|
|
78
108
|
it 'should include the viewer' do
|
79
|
-
@viewer = stub 'viewer'
|
80
109
|
@viewer_writer = stub 'viewer writer'
|
81
110
|
@viewer_writer.should_receive(:hash).and_return "hi Im the viewer"
|
82
|
-
@
|
111
|
+
@viewer_stub.should_receive(:to).and_return @viewer_writer
|
83
112
|
@properties_hash = {
|
84
113
|
"Item#viewer" => [
|
85
114
|
"hi Im the viewer"
|
86
115
|
]
|
87
116
|
}
|
88
117
|
|
89
|
-
@schema_stub.should_receive(:attributes)
|
90
|
-
.and_return :viewer => @viewer, :author => @author_stub
|
118
|
+
@schema_stub.should_receive(:attributes).and_return @attr_stub
|
91
119
|
end
|
92
120
|
|
93
121
|
it 'should include the dateCreated' do
|
@@ -97,8 +125,7 @@ describe Writer::Fetcher::Microdata::ArticleSmall do
|
|
97
125
|
]
|
98
126
|
}
|
99
127
|
|
100
|
-
@schema_stub.should_receive(:attributes)
|
101
|
-
.and_return :dateCreated => 23456235, :author => @author_stub, :viewer => @viewer_stub
|
128
|
+
@schema_stub.should_receive(:attributes).and_return @attr_stub
|
102
129
|
end
|
103
130
|
|
104
131
|
it 'should include the provider' do
|
@@ -109,8 +136,7 @@ describe Writer::Fetcher::Microdata::ArticleSmall do
|
|
109
136
|
]
|
110
137
|
}
|
111
138
|
|
112
|
-
@schema_stub.should_receive(:attributes)
|
113
|
-
.and_return :provider => ["twitter", "fetcher"], :author => @author_stub, :viewer => @viewer_stub
|
139
|
+
@schema_stub.should_receive(:attributes).and_return @attr_stub
|
114
140
|
end
|
115
141
|
|
116
142
|
it 'should include the url' do
|
@@ -119,9 +145,7 @@ describe Writer::Fetcher::Microdata::ArticleSmall do
|
|
119
145
|
"http://myurl.info"
|
120
146
|
]
|
121
147
|
}
|
122
|
-
|
123
|
-
@schema_stub.should_receive(:attributes)
|
124
|
-
.and_return :url => "http://myurl.info", :author => @author_stub, :viewer => @viewer_stub
|
148
|
+
@schema_stub.should_receive(:attributes).and_return @attr_stub
|
125
149
|
end
|
126
150
|
|
127
151
|
after :each do
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Writer::Fetcher::Microdata::UserComments do
|
4
|
+
describe '#hash' do
|
5
|
+
before do
|
6
|
+
@schema_stub = stub 'schema'
|
7
|
+
@creator_stub = stub 'author', :to => stub( :hash => nil)
|
8
|
+
@viewer_stub = stub 'viewer', :to => stub( :hash => nil)
|
9
|
+
@attr_stub = stub 'attr stub'
|
10
|
+
stub1 = stub 'coment1', :to => "hola1"
|
11
|
+
stub2 = stub 'coment2', :to => "hola2"
|
12
|
+
|
13
|
+
@attr_stub.stub(:[]) do |simbol|
|
14
|
+
if simbol == :creator
|
15
|
+
@creator_stub
|
16
|
+
elsif simbol == :additionalType
|
17
|
+
"http://getfetcher.net/Item"
|
18
|
+
elsif simbol == :id
|
19
|
+
"234536234_12345_1234567"
|
20
|
+
elsif simbol == :commentText
|
21
|
+
"some body"
|
22
|
+
elsif simbol == :creator
|
23
|
+
["twitter", "fetcher"]
|
24
|
+
elsif simbol == :commentTime
|
25
|
+
23456235
|
26
|
+
elsif simbol == :url
|
27
|
+
"http://myurl.info"
|
28
|
+
else
|
29
|
+
stub('the hash', :[] => @attr_stub)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should return a hash with the type' do
|
35
|
+
final_hash = {
|
36
|
+
"type" => [
|
37
|
+
'the type'
|
38
|
+
]
|
39
|
+
}
|
40
|
+
@schema_stub.should_receive(:_type).and_return "the type"
|
41
|
+
@schema_stub.should_receive(:attributes).and_return @attr_stub
|
42
|
+
|
43
|
+
writer = Writer::Fetcher::Microdata::UserComments.new @schema_stub
|
44
|
+
writer.hash.should include final_hash
|
45
|
+
end
|
46
|
+
|
47
|
+
describe 'properties hash' do
|
48
|
+
before do
|
49
|
+
@schema_stub.should_receive(:_type).and_return nil
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should include the additionalType' do
|
53
|
+
@properties_hash = {
|
54
|
+
"additionalType" => [
|
55
|
+
"http://getfetcher.net/Item"
|
56
|
+
]
|
57
|
+
}
|
58
|
+
@schema_stub.should_receive(:attributes).and_return @attr_stub
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should include the Item#id' do
|
62
|
+
@properties_hash = {
|
63
|
+
"Item#id" => [
|
64
|
+
"234536234_12345_1234567"
|
65
|
+
]
|
66
|
+
}
|
67
|
+
@schema_stub.should_receive(:attributes).and_return @attr_stub
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should include the commentText' do
|
71
|
+
@properties_hash = {
|
72
|
+
"commentText" => [
|
73
|
+
"some body"
|
74
|
+
]
|
75
|
+
}
|
76
|
+
@schema_stub.should_receive(:attributes).and_return @attr_stub
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should include the creator' do
|
80
|
+
@creator_writer = stub 'creator writer'
|
81
|
+
@creator_writer.should_receive(:hash).and_return "hi Im the creator"
|
82
|
+
@creator_stub.should_receive(:to).and_return @creator_writer
|
83
|
+
@properties_hash = {
|
84
|
+
"creator" => [
|
85
|
+
"hi Im the creator"
|
86
|
+
]
|
87
|
+
}
|
88
|
+
|
89
|
+
@schema_stub.should_receive(:attributes).and_return @attr_stub
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'should include the commentTime' do
|
93
|
+
@properties_hash = {
|
94
|
+
"commentTime" => [
|
95
|
+
23456235
|
96
|
+
]
|
97
|
+
}
|
98
|
+
|
99
|
+
@schema_stub.should_receive(:attributes).and_return @attr_stub
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should include the url' do
|
103
|
+
@properties_hash = {
|
104
|
+
"url" => [
|
105
|
+
"https://www.facebook.com/12345?comment_id=1234567"
|
106
|
+
]
|
107
|
+
}
|
108
|
+
@schema_stub.should_receive(:attributes).and_return @attr_stub
|
109
|
+
end
|
110
|
+
|
111
|
+
after :each do
|
112
|
+
writer = Writer::Fetcher::Microdata::UserComments.new @schema_stub
|
113
|
+
writer.hash["properties"].should include @properties_hash
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fetcher-microdata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
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: 2012-12-
|
12
|
+
date: 2012-12-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: discoverer
|
@@ -77,18 +77,22 @@ files:
|
|
77
77
|
- lib/fetcher-microdata/article_small.rb
|
78
78
|
- lib/fetcher-microdata/person_user.rb
|
79
79
|
- lib/fetcher-microdata/review.rb
|
80
|
+
- lib/fetcher-microdata/user_comments.rb
|
80
81
|
- lib/fetcher-microdata/version.rb
|
81
82
|
- lib/writer/fetcher-microdata/article_small.rb
|
82
83
|
- lib/writer/fetcher-microdata/person_user.rb
|
83
84
|
- lib/writer/fetcher-microdata/review.rb
|
85
|
+
- lib/writer/fetcher-microdata/user_comments.rb
|
84
86
|
- spec/fetcher/microdata/article_small_spec.rb
|
85
87
|
- spec/fetcher/microdata/person_user_spec.rb
|
86
88
|
- spec/fetcher/microdata/review_spec.rb
|
89
|
+
- spec/fetcher/microdata/user_comments_spec.rb
|
87
90
|
- spec/fetcher/microdata_spec.rb
|
88
91
|
- spec/spec_helper.rb
|
89
92
|
- spec/writer/fetcher/microdata/article_small_spec.rb
|
90
93
|
- spec/writer/fetcher/microdata/person_user_spec.rb
|
91
94
|
- spec/writer/fetcher/microdata/review_spec.rb
|
95
|
+
- spec/writer/fetcher/microdata/user_comments_spec.rb
|
92
96
|
homepage: http://github.com/Fetcher/fetcher-microdata
|
93
97
|
licenses: []
|
94
98
|
post_install_message:
|
@@ -117,8 +121,10 @@ test_files:
|
|
117
121
|
- spec/fetcher/microdata/article_small_spec.rb
|
118
122
|
- spec/fetcher/microdata/person_user_spec.rb
|
119
123
|
- spec/fetcher/microdata/review_spec.rb
|
124
|
+
- spec/fetcher/microdata/user_comments_spec.rb
|
120
125
|
- spec/fetcher/microdata_spec.rb
|
121
126
|
- spec/spec_helper.rb
|
122
127
|
- spec/writer/fetcher/microdata/article_small_spec.rb
|
123
128
|
- spec/writer/fetcher/microdata/person_user_spec.rb
|
124
129
|
- spec/writer/fetcher/microdata/review_spec.rb
|
130
|
+
- spec/writer/fetcher/microdata/user_comments_spec.rb
|