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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7a283bd077d0807c832bb7772d904597da3a9ae0
4
- data.tar.gz: 4067c283aafb92a3240b51ecdd3030ddb3bf5391
3
+ metadata.gz: 66830b65cb32b2621ca5a1bd39c998bcf31a85d3
4
+ data.tar.gz: 0eaef59029d535f119636e3576d490f698332106
5
5
  SHA512:
6
- metadata.gz: 032a7211bcaf5a3732cd147b80aef9c4362b2a71941e570e8ffed243ea16e4f16c72c0473a063d18decf24ff674457c937cf94134aa171f45e0a061925257de7
7
- data.tar.gz: f528831eec780a89c1f867f095c25057c526f0ba5695e9bacbca37c6303d16fe270cd2106183f510749240d82cdd66088a612274ee8a8e96435b8837992c6070
6
+ metadata.gz: d3f50ceed01ec6cef120233ead2fc7f58c640e91a87538bacf15b16e998677dd619ec494429b6d2e3e41298ffd03f6cf1bb128ce10848dd42048804183cb5a27
7
+ data.tar.gz: 5c3575dfb1b5a48bd704419a95f6770ff4a01847d698985b46d6b3a2762f1868568eba0bbb53a6145689b3778b864d491f1a538aad4a5a73b1a541293c7459bb
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pavlov_rss (0.0.1)
4
+ pavlov_rss (0.0.2)
5
5
  activesupport
6
6
  nokogiri
7
7
 
@@ -4,12 +4,19 @@ require 'active_support/core_ext'
4
4
 
5
5
  module PavlovRss
6
6
  class Reader
7
- def initialize(urls)
8
- @urls = Array(urls)
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 = @urls.map {|url| Nokogiri.XML(open(url,&:read))}
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
@@ -1,3 +1,3 @@
1
1
  module PavlovRss
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pavlov_rss
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Minwoo Lee