feedutils 0.3.1 → 0.3.2

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.
data/Manifest.txt CHANGED
@@ -5,7 +5,9 @@ Rakefile
5
5
  lib/feedutils.rb
6
6
  lib/feedutils/builder/atom.rb
7
7
  lib/feedutils/builder/rss.rb
8
- lib/feedutils/utils.rb
8
+ lib/feedutils/feed.rb
9
+ lib/feedutils/item.rb
10
+ lib/feedutils/parser.rb
9
11
  lib/feedutils/version.rb
10
12
  test/helper.rb
11
13
  test/test_atom.rb
data/lib/feedutils.rb CHANGED
@@ -15,7 +15,9 @@ require 'feedutils/version' # let it always go first
15
15
  require 'feedutils/builder/atom'
16
16
  require 'feedutils/builder/rss'
17
17
 
18
- require 'feedutils/utils'
18
+ require 'feedutils/feed'
19
+ require 'feedutils/item'
20
+ require 'feedutils/parser'
19
21
 
20
22
 
21
23
  module FeedUtils
@@ -0,0 +1,52 @@
1
+ module FeedUtils
2
+
3
+ class Feed
4
+ attr_accessor :object
5
+
6
+ attr_accessor :format # e.g. atom|rss 2.0|etc.
7
+ attr_accessor :title
8
+ attr_accessor :title_type # e.g. text|html|html-escaped (optional) -use - why?? why not??
9
+ attr_accessor :url
10
+
11
+ attr_accessor :items
12
+
13
+ def summary?() @summary.nil? == false; end
14
+ # no summary? try/return title2
15
+ def summary() summary? ? @summary : @title2; end
16
+ attr_writer :summary # e.g. description (rss)
17
+
18
+ attr_accessor :summary_type # e.g. text|html|html-escaped
19
+
20
+ def title2?() @title2.nil? == false; end
21
+ attr_accessor :title2 # e.g. subtitle (atom)
22
+
23
+ attr_accessor :title2_type # e.g. text|html|html-escaped
24
+
25
+ def published?() @published.nil? == false; end
26
+ # no published date? try/return updated or built
27
+ def published
28
+ if published?
29
+ @published
30
+ elsif updated?
31
+ @updated
32
+ else
33
+ @built
34
+ end
35
+ end
36
+ attr_writer :published
37
+
38
+ def updated?() @updated.nil? == false; end
39
+ attr_accessor :updated
40
+
41
+ def built?() @built.nil? == false; end
42
+ attr_accessor :built
43
+
44
+ attr_accessor :generator
45
+
46
+
47
+ ## fix:
48
+ # add pretty printer/inspect (exclude object)
49
+
50
+ end # class Feed
51
+
52
+ end # module FeedUtils
@@ -0,0 +1,42 @@
1
+ module FeedUtils
2
+
3
+ class Item
4
+ attr_accessor :object # orginal object (e.g RSS item or ATOM entry etc.)
5
+
6
+ attr_accessor :title
7
+ attr_accessor :title_type # optional for now (text|html|html-escaped) - not yet set
8
+ attr_accessor :url # todo: rename to link (use alias) ??
9
+
10
+
11
+ # no content? try/return summary
12
+ def content() content? ? @content : @summary; end
13
+ def content?() @content.nil? == false; end
14
+ attr_writer :content
15
+
16
+ attr_accessor :content_type # optional for now (text|html|html-escaped|binary-base64) - not yet set
17
+
18
+ # no summary? try/return content
19
+ def summary() summary? ? @summary : @content; end
20
+ def summary?() @summary.nil? == false; end
21
+ attr_writer :summary
22
+
23
+ attr_accessor :summary_type # optional for now (text|html|html-escaped) - not yet set
24
+
25
+ ## todo: add summary (alias description) ???
26
+ ## todo: add author/authors
27
+ ## todo: add category/categories
28
+
29
+ # no published date? try/return updated
30
+ def published() published? ? @published : @updated; end
31
+ def published?() @published.nil? == false; end
32
+ attr_writer :published
33
+
34
+ def updated?() @updated.nil? == false; end
35
+ attr_accessor :updated
36
+
37
+ attr_accessor :guid # todo: rename to id (use alias) ??
38
+
39
+
40
+ end # class Item
41
+
42
+ end # module FeedUtils
@@ -0,0 +1,42 @@
1
+
2
+ module FeedUtils
3
+
4
+
5
+ class Parser
6
+
7
+ include LogUtils::Logging
8
+
9
+ ### convenience class/factory method
10
+ def self.parse( xml, opts={} )
11
+ self.new( xml ).parse
12
+ end
13
+
14
+ ### Note: lets keep/use same API as RSS::Parser for now
15
+ def initialize( xml )
16
+ @xml = xml
17
+ end
18
+
19
+ def parse
20
+ parser = RSS::Parser.new( @xml )
21
+ parser.do_validate = false
22
+ parser.ignore_unknown_element = true
23
+
24
+ puts "Parsing feed..."
25
+ feed_wild = parser.parse # not yet normalized
26
+
27
+ logger.debug " feed.class=#{feed_wild.class.name}"
28
+
29
+ if feed_wild.is_a?( RSS::Atom::Feed )
30
+ feed = AtomFeedBuilder.build( feed_wild )
31
+ else # -- assume RSS::Rss::Feed
32
+ feed = RssFeedBuilder.build( feed_wild )
33
+ end
34
+
35
+ puts "== #{feed.format} / #{feed.title} =="
36
+ feed # return new (normalized) feed
37
+ end
38
+
39
+ end # class Parser
40
+
41
+
42
+ end # module FeedUtils
@@ -1,4 +1,4 @@
1
1
 
2
2
  module FeedUtils
3
- VERSION = '0.3.1'
3
+ VERSION = '0.3.2'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: feedutils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-27 00:00:00.000000000 Z
12
+ date: 2013-09-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: logutils
16
- requirement: &74300430 !ruby/object:Gem::Requirement
16
+ requirement: &82615740 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0.5'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *74300430
24
+ version_requirements: *82615740
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rdoc
27
- requirement: &74300030 !ruby/object:Gem::Requirement
27
+ requirement: &82615490 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '3.10'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *74300030
35
+ version_requirements: *82615490
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: hoe
38
- requirement: &74299400 !ruby/object:Gem::Requirement
38
+ requirement: &82615190 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '3.3'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *74299400
46
+ version_requirements: *82615190
47
47
  description: feedutils - web feed parser and normalizer (RSS 2.0, Atom, etc.)
48
48
  email: webslideshow@googlegroups.com
49
49
  executables: []
@@ -58,7 +58,9 @@ files:
58
58
  - lib/feedutils.rb
59
59
  - lib/feedutils/builder/atom.rb
60
60
  - lib/feedutils/builder/rss.rb
61
- - lib/feedutils/utils.rb
61
+ - lib/feedutils/feed.rb
62
+ - lib/feedutils/item.rb
63
+ - lib/feedutils/parser.rb
62
64
  - lib/feedutils/version.rb
63
65
  - test/helper.rb
64
66
  - test/test_atom.rb
@@ -1,170 +0,0 @@
1
-
2
- module FeedUtils
3
-
4
-
5
- class Feed
6
- attr_accessor :object
7
-
8
- attr_accessor :format # e.g. atom|rss 2.0|etc.
9
- attr_accessor :title
10
- attr_accessor :title_type # e.g. text|html|html-escaped (optional) -use - why?? why not??
11
- attr_accessor :url
12
-
13
- attr_accessor :items
14
-
15
- attr_accessor :summary # e.g. description (rss)
16
- attr_accessor :summary_type # e.g. text|html|html-escaped
17
- attr_accessor :title2 # e.g. subtitle (atom)
18
- attr_accessor :title2_type # e.g. text|html|html-escaped
19
-
20
- attr_accessor :published
21
- attr_accessor :updated
22
- attr_accessor :built
23
-
24
- attr_accessor :generator
25
-
26
-
27
- def title2?
28
- @title2.nil? == false
29
- end
30
-
31
- def summary?
32
- @summary.nil? == false
33
- end
34
-
35
- def built?
36
- @built.nil? == false
37
- end
38
-
39
- def updated?
40
- @updated.nil? == false
41
- end
42
-
43
- def published?
44
- @published.nil? == false
45
- end
46
-
47
-
48
- def summary
49
- # no summary? try/return title2
50
- if summary?
51
- @summary
52
- else
53
- @title2
54
- end
55
- end
56
-
57
- def published
58
- # no published date? try/return updated or built
59
- if published?
60
- @published
61
- elsif updated?
62
- @updated
63
- else
64
- @built
65
- end
66
- end
67
-
68
- ## fix:
69
- # add pretty printer/inspect (exclude object)
70
-
71
- end # class Feed
72
-
73
-
74
- class Item
75
- attr_accessor :object # orginal object (e.g RSS item or ATOM entry etc.)
76
-
77
- attr_accessor :title
78
- attr_accessor :title_type # optional for now (text|html|html-escaped) - not yet set
79
- attr_accessor :url # todo: rename to link (use alias) ??
80
- attr_accessor :content
81
- attr_accessor :content_type # optional for now (text|html|html-escaped|binary-base64) - not yet set
82
- attr_accessor :summary
83
- attr_accessor :summary_type # optional for now (text|html|html-escaped) - not yet set
84
-
85
- ## todo: add summary (alias description) ???
86
- ## todo: add author/authors
87
- ## todo: add category/categories
88
-
89
- attr_accessor :published
90
- attr_accessor :updated
91
-
92
- attr_accessor :guid # todo: rename to id (use alias) ??
93
-
94
-
95
- def summary?
96
- @summary.nil? == false
97
- end
98
-
99
- def content?
100
- @content.nil? == false
101
- end
102
-
103
- def published?
104
- @published.nil? == false
105
- end
106
-
107
- def updated?
108
- @updated.nil? == false
109
- end
110
-
111
- def content
112
- # no content? try/return summary
113
- if content?
114
- @content
115
- else
116
- @summary
117
- end
118
- end
119
-
120
- def published
121
- # no published date? try/return updated
122
- if published?
123
- @published
124
- else
125
- @updated
126
- end
127
- end
128
-
129
-
130
- end # class Item
131
-
132
-
133
- class Parser
134
-
135
- include LogUtils::Logging
136
-
137
- ### Note: lets keep/use same API as RSS::Parser for now
138
- def initialize( xml )
139
- @xml = xml
140
- end
141
-
142
- def parse
143
- parser = RSS::Parser.new( @xml )
144
- parser.do_validate = false
145
- parser.ignore_unknown_element = true
146
-
147
- puts "Parsing feed..."
148
- feed_wild = parser.parse # not yet normalized
149
-
150
- logger.debug " feed.class=#{feed_wild.class.name}"
151
-
152
- if feed_wild.is_a?( RSS::Atom::Feed )
153
- feed = AtomFeedBuilder.build( feed_wild )
154
- else # -- assume RSS::Rss::Feed
155
- feed = RssFeedBuilder.build( feed_wild )
156
- end
157
-
158
- puts "== #{feed.format} / #{feed.title} =="
159
- feed # return new (normalized) feed
160
- end
161
-
162
- ### convenience class/factory method
163
- def self.parse( xml, opts={} )
164
- self.new( xml ).parse
165
- end
166
-
167
- end # class Parser
168
-
169
-
170
- end # module FeedUtils