pavlov_rss 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/pavlov_rss/reader.rb +10 -3
- data/lib/pavlov_rss/version.rb +1 -1
- data/spec/lib/pavlov_rss/reader_spec.rb +51 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66830b65cb32b2621ca5a1bd39c998bcf31a85d3
|
4
|
+
data.tar.gz: 0eaef59029d535f119636e3576d490f698332106
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3f50ceed01ec6cef120233ead2fc7f58c640e91a87538bacf15b16e998677dd619ec494429b6d2e3e41298ffd03f6cf1bb128ce10848dd42048804183cb5a27
|
7
|
+
data.tar.gz: 5c3575dfb1b5a48bd704419a95f6770ff4a01847d698985b46d6b3a2762f1868568eba0bbb53a6145689b3778b864d491f1a538aad4a5a73b1a541293c7459bb
|
data/Gemfile.lock
CHANGED
data/lib/pavlov_rss/reader.rb
CHANGED
@@ -4,12 +4,19 @@ require 'active_support/core_ext'
|
|
4
4
|
|
5
5
|
module PavlovRss
|
6
6
|
class Reader
|
7
|
-
def initialize(
|
8
|
-
@
|
7
|
+
def initialize(urls_or_lambdas)
|
8
|
+
@lambdas = Array(urls_or_lambdas).map do |url_or_lambda|
|
9
|
+
case url_or_lambda
|
10
|
+
when String
|
11
|
+
lambda {open(url_or_lambda, &:read)}
|
12
|
+
else
|
13
|
+
url_or_lambda
|
14
|
+
end
|
15
|
+
end
|
9
16
|
end
|
10
17
|
|
11
18
|
def check
|
12
|
-
now = @
|
19
|
+
now = @lambdas.map(&:call).map(&Nokogiri.method(:XML))
|
13
20
|
@prev ||= now
|
14
21
|
result = @prev.zip(now).map do |p,n|
|
15
22
|
new_items p, n
|
data/lib/pavlov_rss/version.rb
CHANGED
@@ -123,4 +123,55 @@ describe PavlovRss::Reader do
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
end
|
126
|
+
|
127
|
+
context 'with a labmda' do
|
128
|
+
before do
|
129
|
+
@url = "http://example.com/rss.xml"
|
130
|
+
@reader = PavlovRss::Reader.new lambda { open(@url, &:read) }
|
131
|
+
end
|
132
|
+
describe '#check' do
|
133
|
+
it 'works' do
|
134
|
+
FakeWeb.register_uri(:get, @url, [
|
135
|
+
{body: feed('rss0.xml')},
|
136
|
+
{body: feed('rss1.xml')},
|
137
|
+
{body: feed('rss2.xml')},
|
138
|
+
{body: feed('rss3.xml')},
|
139
|
+
{body: feed('rss4.xml')},
|
140
|
+
{body: feed('rss5.xml')},
|
141
|
+
])
|
142
|
+
@reader.check
|
143
|
+
@reader.check.should == [[
|
144
|
+
{
|
145
|
+
"title"=>"title1",
|
146
|
+
"link"=>"http://example.com/title1",
|
147
|
+
"description"=>"description1"
|
148
|
+
}]]
|
149
|
+
@reader.check.should == [[
|
150
|
+
{
|
151
|
+
"title"=>"title2",
|
152
|
+
"link"=>"http://example.com/title2",
|
153
|
+
"description"=>"description2"
|
154
|
+
}]]
|
155
|
+
@reader.check.should == [[
|
156
|
+
{
|
157
|
+
"title"=>"title3",
|
158
|
+
"link"=>"http://example.com/title3",
|
159
|
+
"description"=>"description3"
|
160
|
+
}]]
|
161
|
+
@reader.check.should == [[
|
162
|
+
{
|
163
|
+
"title"=>"title4",
|
164
|
+
"link"=>"http://example.com/title4",
|
165
|
+
"description"=>"description4"
|
166
|
+
}]]
|
167
|
+
@reader.check.should == [[
|
168
|
+
{
|
169
|
+
"title"=>"title5",
|
170
|
+
"link"=>"http://example.com/title5",
|
171
|
+
"description"=>"description5"
|
172
|
+
}]]
|
173
|
+
@reader.check.should == [[]]
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
126
177
|
end
|