Parent

Class Index [+]

Quicksearch

SimpleRSS

Constants

VERSION

Attributes

items[R]
source[R]

Public Class Methods

feed_tags() click to toggle source
    # File lib/simple-rss.rb, line 52
52:                 def feed_tags
53:                         @@feed_tags
54:                 end
feed_tags=(ft) click to toggle source
    # File lib/simple-rss.rb, line 55
55:                 def feed_tags=(ft)
56:                         @@feed_tags = ft
57:                 end
item_tags() click to toggle source
    # File lib/simple-rss.rb, line 59
59:                 def item_tags
60:                         @@item_tags
61:                 end
item_tags=(it) click to toggle source
    # File lib/simple-rss.rb, line 62
62:                 def item_tags=(it)
63:                         @@item_tags = it
64:                 end
new(source, options={}) click to toggle source
    # File lib/simple-rss.rb, line 40
40:         def initialize(source, options={})
41:                 @source = source.respond_to?(:read) ? source.read : source.to_s
42:                 @items = Array.new
43:     @options = Hash.new.update(options)
44:     
45:                 parse
46:         end
parse(source, options={}) click to toggle source

The strict attribute is for compatibility with Ruby’s standard RSS parser

    # File lib/simple-rss.rb, line 67
67:                 def parse(source, options={})
68:                         new source, options
69:                 end

Public Instance Methods

channel() click to toggle source
    # File lib/simple-rss.rb, line 48
48:         def channel() self end
Also aliased as: feed
feed() click to toggle source
Alias for: channel

Private Instance Methods

clean_content(tag, attrs, content) click to toggle source
     # File lib/simple-rss.rb, line 138
138:         def clean_content(tag, attrs, content)
139:                 content = content.to_s
140:                 case tag
141:                         when :pubDate, :lastBuildDate, :published, :updated, :expirationDate, :modified, :'dc:date'
142:                                 Time.parse(content) rescue unescape(content)
143:                         when :author, :contributor, :skipHours, :skipDays
144:                                 unescape(content.gsub(/<.*?>/,''))
145:                         else
146:                                 content.empty? && "#{attrs} " =~ /href=['"]?([^'"]*)['" ]/i ? $1.strip : unescape(content)
147:                 end
148:         end
clean_tag(tag) click to toggle source
     # File lib/simple-rss.rb, line 150
150:         def clean_tag(tag)
151:                 tag.to_s.gsub(':','_').intern
152:         end
parse() click to toggle source
     # File lib/simple-rss.rb, line 74
 74:         def parse
 75:           raise SimpleRSSError, "Poorly formatted feed" unless @source =~ %{<(channel|feed).*?>.*?</(channel|feed)>}i
 76:           
 77:                 # Feed's title and link
 78:                 feed_content = $1 if @source =~ %{(.*?)<(rss:|atom:)?(item|entry).*?>.*?</(rss:|atom:)?(item|entry)>}i
 79:                 
 80:                 @@feed_tags.each do |tag|
 81:                         if feed_content && feed_content =~ %{<(rss:|atom:)?#{tag}(.*?)>(.*?)</(rss:|atom:)?#{tag}>}i
 82:                                 nil
 83:                         elsif feed_content && feed_content =~ %{<(rss:|atom:)?#{tag}(.*?)\/\s*>}i
 84:                                 nil
 85:                         elsif @source =~ %{<(rss:|atom:)?#{tag}(.*?)>(.*?)</(rss:|atom:)?#{tag}>}i
 86:                                 nil
 87:                         elsif @source =~ %{<(rss:|atom:)?#{tag}(.*?)\/\s*>}i
 88:                                 nil
 89:                         end
 90:                         
 91:                         if $2 || $3
 92:         tag_cleaned = clean_tag(tag)
 93:         instance_variable_set("@#{ tag_cleaned }", clean_content(tag, $2, $3))
 94:         self.class.send(:attr_reader, tag_cleaned)
 95:                         end
 96:                 end
 97: 
 98:                 # RSS items' title, link, and description
 99:                 @source.scan( %{<(rss:|atom:)?(item|entry)([\s][^>]*)?>(.*?)</(rss:|atom:)?(item|entry)>}i ) do |match|
100:                         item = Hash.new
101:                         @@item_tags.each do |tag|
102:                           if tag.to_s.include?("+")
103:                             tag_data = tag.to_s.split("+")
104:                             tag = tag_data[0]
105:                             rel = tag_data[1]
106:                             
107:                                 if match[3] =~ %{<(rss:|atom:)?#{tag}(.*?)rel=['"]#{rel}['"](.*?)>(.*?)</(rss:|atom:)?#{tag}>}i
108:             nil
109:                                 elsif match[3] =~ %{<(rss:|atom:)?#{tag}(.*?)rel=['"]#{rel}['"](.*?)/\s*>}i
110:                                   nil
111:                                 end
112:                                 item[clean_tag("#{tag}+#{rel}")] = clean_content(tag, $3, $4) if $3 || $4
113:                         elsif tag.to_s.include?("#")
114:                             tag_data = tag.to_s.split("#")
115:                             tag = tag_data[0]
116:                             attrib = tag_data[1]
117:                                 if match[3] =~ %{<(rss:|atom:)?#{tag}(.*?)#{attrib}=['"](.*?)['"](.*?)>(.*?)</(rss:|atom:)?#{tag}>}i
118:             nil
119:                                 elsif match[3] =~ %{<(rss:|atom:)?#{tag}(.*?)#{attrib}=['"](.*?)['"](.*?)/\s*>}i
120:                                   nil
121:                                 end
122:                                 item[clean_tag("#{tag}_#{attrib}")] = clean_content(tag, attrib, $3) if $3
123:                     else
124:                                 if match[3] =~ %{<(rss:|atom:)?#{tag}(.*?)>(.*?)</(rss:|atom:)?#{tag}>}i
125:                                         nil
126:                                 elsif match[3] =~ %{<(rss:|atom:)?#{tag}(.*?)/\s*>}i
127:                                         nil
128:                                 end
129:                                 item[clean_tag(tag)] = clean_content(tag, $2, $3) if $2 || $3
130:                                 end
131:                         end
132:                         def item.method_missing(name, *args) self[name] end
133:                         @items << item
134:                 end
135: 
136:         end
unescape(content) click to toggle source
     # File lib/simple-rss.rb, line 154
154:   def unescape(content)
155:         if content =~ /([^-_.!~*'()a-zA-Z\d;\/?:@&=+$,\[\]]%)/ then
156:                 CGI.unescape(content).gsub(/(<!\[CDATA\[|\]\]>)/,'').strip
157:         else
158:                 content.gsub(/(<!\[CDATA\[|\]\]>)/,'').strip
159:         end
160:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.