Class: FeedParser::RSSItem
- Defined in:
- lib/feedparser/feedparser.rb
Instance Attribute Summary
Attributes inherited from FeedItem
#cacheditem, #categories, #content, #creators, #date, #enclosures, #feed, #link, #links, #subject, #title, #xml
Instance Method Summary collapse
Methods inherited from FeedItem
#creator, #initialize, #to_html, #to_html_with_headers, #to_s, #to_text
Constructor Details
This class inherits a constructor from FeedParser::FeedItem
Instance Method Details
#parse(item) ⇒ Object
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/feedparser/feedparser.rb', line 256 def parse(item) # Title. If no title, use the pubDate as fallback. if ((e = item.elements['title'] || item.elements['rss:title']) && e.text) || ((e = item.elements['pubDate'] || item.elements['rss:pubDate']) && e.text) @title = e.text.unescape_html.toUTF8(@feed.encoding).html2text.rmWhiteSpace! end # Link if ((e = item.elements['link'] || item.elements['rss:link']) && e.text)|| (e = item.elements['guid'] || item.elements['rss:guid'] and not (e.attribute('isPermaLink') and e.attribute('isPermaLink').value == 'false')) self.link = e.text.rmWhiteSpace! end # Content if (e = item.elements['content:encoded']) || (e = item.elements['description'] || item.elements['rss:description']) @content = FeedParser::getcontent(e, @feed) end # Date if e = item.elements['dc:date'] || item.elements['pubDate'] || item.elements['rss:pubDate'] begin @date = Time::xmlschema(e.text) rescue begin @date = Time::rfc2822(e.text) rescue begin @date = Time::parse(e.text) rescue @date = nil end end end end # Creator if (e = item.elements['dc:creator'] || item.elements['author'] || item.elements['rss:author']) && e.text @creators << e.text.unescape_html.toUTF8(@feed.encoding).rmWhiteSpace! end @creators << @feed.creator if @creators.empty? and @feed.creator # Subject if (e = item.elements['dc:subject']) && e.text @subject = e.text.unescape_html.toUTF8(@feed.encoding).rmWhiteSpace! end # Categories cat_elts = [] item.each_element('dc:category') { |e| cat_elts << e if e.text } item.each_element('category') { |e| cat_elts << e if e.text } item.each_element('rss:category') { |e| cat_elts << e if e.text } cat_elts.each do |e| @categories << e.text.unescape_html.toUTF8(@feed.encoding).rmWhiteSpace! end # Enclosures item.each_element('enclosure') do |e| url = e.attribute('url').value if e.attribute('url') length = e.attribute('length').value if e.attribute('length') type = e.attribute('type').value if e.attribute('type') @enclosures << [ url, length, type ] if url end end |