Class: FeedAbstract::Item::RSS

Inherits:
Object
  • Object
show all
Includes:
FeedAbstractMixins::RSS
Defined in:
lib/feed-abstract/item/rss.rb

Direct Known Subclasses

RDF

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item, channel) ⇒ RSS

Returns a new instance of RSS.



10
11
12
13
# File 'lib/feed-abstract/item/rss.rb', line 10

def initialize(item,channel)
  @item = @source = item
  @channel = channel
end

Instance Attribute Details

#channelObject (readonly)

Returns the value of attribute channel.



8
9
10
# File 'lib/feed-abstract/item/rss.rb', line 8

def channel
  @channel
end

#itemObject (readonly)

Returns the value of attribute item.



8
9
10
# File 'lib/feed-abstract/item/rss.rb', line 8

def item
  @item
end

#sourceObject (readonly)

Returns the value of attribute source.



8
9
10
# File 'lib/feed-abstract/item/rss.rb', line 8

def source
  @source
end

Instance Method Details

#authorObject

The author list as a string, joined with a comma.



44
45
46
# File 'lib/feed-abstract/item/rss.rb', line 44

def author
  (self.authors.empty?) ? '' : self.authors.join(', ')
end

#authorsObject

The author list (a merge of the RSS author and dc:creator elements) as an array.



36
37
38
39
40
41
# File 'lib/feed-abstract/item/rss.rb', line 36

def authors
  if self.channel.generator == 'Twitter'
    return [@item.title.split(':')[0]]
  end
  [@item.author, ((@item.dc_creators.empty?) ? nil : @item.dc_creators.collect{|c| c.content})].flatten.uniq.compact.reject{|au| au == '' || au.match(/^\s+$/)}
end

#categoriesObject

The category list as an array.



59
60
61
62
63
64
65
# File 'lib/feed-abstract/item/rss.rb', line 59

def categories
  if self.channel.generator == 'Twitter'
    return @item.title.scan(/#([^#\s]+)/).flatten
  end
  return [] if @item.categories.empty?
  @item.categories.collect{|c| c.content}.reject{|c| c == '' || c.match(/^\s+$/)}
end

#categoryObject

The category list as a string, joined with a comma.



68
69
70
71
72
73
74
# File 'lib/feed-abstract/item/rss.rb', line 68

def category
  if self.channel.generator == 'Twitter'
    return self.categories.join(', ')
  end
  return '' if @item.categories.empty? 
  @item.categories.collect{|c| c.content}.join(', ')
end

#contentObject

The full content of this item, theoretically.



21
22
23
24
# File 'lib/feed-abstract/item/rss.rb', line 21

def content
  return '' if @item.content_encoded.nil?
  @item.content_encoded
end

#contributorObject

The contributor list as a string joined with a comma.



54
55
56
# File 'lib/feed-abstract/item/rss.rb', line 54

def contributor
  (self.contributors.empty?) ? '' : self.contributors.join(', ')
end

#contributorsObject

The contributors (parsed from the dc:contributor element) as an array.



49
50
51
# File 'lib/feed-abstract/item/rss.rb', line 49

def contributors
  (@item.dc_contributors.empty?) ? [] : @item.dc_contributors.reject{|au| au == '' || au.match(/^\s+$/)}
end

#guidObject

A globally unique id.



87
88
89
90
# File 'lib/feed-abstract/item/rss.rb', line 87

def guid
  return '' if @item.guid.nil?
  @item.guid.content
end


31
32
33
# File 'lib/feed-abstract/item/rss.rb', line 31

def link
  @item.link
end

#rightsObject

Copyright info.



77
78
79
# File 'lib/feed-abstract/item/rss.rb', line 77

def rights
  (@item.dc_rights.nil?) ? '' : @item.dc_rights
end

#summaryObject



26
27
28
29
# File 'lib/feed-abstract/item/rss.rb', line 26

def summary
  return '' if @item.description.nil?
  @item.description
end

#titleObject



15
16
17
18
# File 'lib/feed-abstract/item/rss.rb', line 15

def title
  return '' if @item.title.nil?
  @item.title
end

#updatedObject Also known as: published



81
82
83
# File 'lib/feed-abstract/item/rss.rb', line 81

def updated
  (@item.pubDate.nil?) ? '' : @item.pubDate
end