rss_detector 0.1.0 → 0.1.1

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.
@@ -2,41 +2,37 @@
2
2
  require "rss_detector/version"
3
3
  require 'nokogiri'
4
4
 
5
- class RSSDetector
5
+ module RSSDetector
6
6
  # xpath for feed
7
7
  RSS_XPATH = '//link[@rel="alternate"][@type="application/rss+xml"]'
8
8
  ATOM_XPATH = '//link[@rel="alternate"][@type="application/atom+xml"]'
9
9
 
10
- public
11
- def RSSDetector::detect(doc)
10
+ class << self
11
+ public
12
+ def detect(doc)
13
+ # create html from string
14
+ html = Nokogiri::HTML(doc)
12
15
 
13
- # create html from string
14
- html = Nokogiri::HTML(doc)
16
+ # detect rss and atom
17
+ rss_feeds = detectFeed(html, RSS_XPATH)
18
+ atom_feeds = detectFeed(html, ATOM_XPATH)
15
19
 
16
- # detect rss and atom
17
- @rss_feeds = detectFeed(html, RSS_XPATH)
18
- @atom_feeds = detectFeed(html, ATOM_XPATH)
19
-
20
- return @rss_feeds + @atom_feeds
21
- end
22
-
23
- private
24
- def RSSDetector::detectFeed(html, feed_xpath)
25
-
26
- # feed list
27
- @feeds = Array.new
20
+ rss_feeds + atom_feeds
21
+ end
28
22
 
29
- # discover feed
30
- html.xpath(feed_xpath).each do |link|
23
+ private
24
+ def detectFeed(html, feed_xpath)
25
+ # discover feed
26
+ html.xpath(feed_xpath).inject(Array.new) do |feeds, link|
31
27
 
32
- # get feed title and url
33
- @feed_title = link.attribute("title")
34
- @feed_url = link.attribute("href")
28
+ # get feed title and url
29
+ feed_title = link.attribute("title")
30
+ feed_url = link.attribute("href")
35
31
 
36
- # push hash to array
37
- @feeds << {title: @feed_title, url: @feed_url}
32
+ # push hash to array
33
+ feeds << {title: feed_title, url: feed_url}
34
+ feeds
35
+ end
38
36
  end
39
-
40
- return @feeds
41
37
  end
42
38
  end
@@ -1,3 +1,3 @@
1
- class RssDetector
2
- VERSION = "0.1.0"
1
+ module RssDetector
2
+ VERSION = "0.1.1"
3
3
  end
@@ -5,21 +5,21 @@ describe RSSDetector do
5
5
  context 'init' do
6
6
  describe '#detect' do
7
7
  context 'nil input' do
8
- it 'should be no feed' do
8
+ it 'no feed' do
9
9
  feeds = RSSDetector::detect(nil)
10
10
  feeds.size.should == 0
11
11
  end
12
12
  end
13
13
 
14
14
  context 'null string input' do
15
- it 'should be no feed' do
15
+ it 'no feed' do
16
16
  feeds = RSSDetector::detect('')
17
17
  feeds.size.should == 0
18
18
  end
19
19
  end
20
20
 
21
21
  context 'no contain feed input' do
22
- it 'should be no feed' do
22
+ it 'no feed' do
23
23
  input = <<-EOS
24
24
  <html><head>
25
25
  </head></html>
@@ -31,7 +31,7 @@ describe RSSDetector do
31
31
  end
32
32
 
33
33
  context 'contain 1 rss feed input' do
34
- it 'should be 1 rss feed' do
34
+ it '1 rss feed' do
35
35
  input = <<-EOS
36
36
  <html><head>
37
37
  <link rel="alternate" type="application/rss+xml" title="test_rss_feed_title" href="http://test_rss_feed_url/"/>
@@ -46,7 +46,7 @@ describe RSSDetector do
46
46
  end
47
47
 
48
48
  context 'contain 2 rss feed input' do
49
- it 'should be 2 rss feed' do
49
+ it '2 rss feed' do
50
50
  input = <<-EOS
51
51
  <html><head>
52
52
  <link rel="alternate" type="application/rss+xml" title="test_rss_feed_title_1" href="http://test_rss_feed_url_1/"/>
@@ -64,7 +64,7 @@ describe RSSDetector do
64
64
  end
65
65
 
66
66
  context 'contain 1 atom feed input' do
67
- it 'should be 1 atom feed' do
67
+ it '1 atom feed' do
68
68
  input = <<-EOS
69
69
  <html><head>
70
70
  <link rel="alternate" type="application/atom+xml" title="test_atom_feed_title" href="http://test_atom_feed_url/"/>
@@ -79,7 +79,7 @@ describe RSSDetector do
79
79
  end
80
80
 
81
81
  context 'contain 2 atom feed input' do
82
- it 'should be 2 atom feed' do
82
+ it '2 atom feed' do
83
83
  input = <<-EOS
84
84
  <html><head>
85
85
  <link rel="alternate" type="application/atom+xml" title="test_atom_feed_title_1" href="http://test_atom_feed_url_1/"/>
@@ -97,7 +97,7 @@ describe RSSDetector do
97
97
  end
98
98
 
99
99
  context 'contain rss and atom feed input' do
100
- it 'should be rss and atom feed' do
100
+ it 'rss and atom feed' do
101
101
  input = <<-EOS
102
102
  <html><head>
103
103
  <link rel="alternate" type="application/rss+xml" title="test_rss_feed_title" href="http://test_rss_feed_url/"/>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rss_detector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
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: 2013-01-09 00:00:00.000000000 Z
12
+ date: 2013-02-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -76,7 +76,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
76
  version: '0'
77
77
  segments:
78
78
  - 0
79
- hash: 3615957483934444237
79
+ hash: -3705627074930154090
80
80
  required_rubygems_version: !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  version: '0'
86
86
  segments:
87
87
  - 0
88
- hash: 3615957483934444237
88
+ hash: -3705627074930154090
89
89
  requirements: []
90
90
  rubyforge_project:
91
91
  rubygems_version: 1.8.24