Object
# File lib/simple-rss.rb, line 48
48: def channel() self end
# 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
# File lib/simple-rss.rb, line 150
150: def clean_tag(tag)
151: tag.to_s.gsub(':','_').intern
152: end
# 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
# 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.
Generated with the Darkfish Rdoc Generator 1.1.6.