class RSS2Mail::RSS::Item
Public Class Methods
new(item)
click to toggle source
# File lib/rss2mail/rss.rb 98 def initialize(item) 99 @item = item 100 end
Public Instance Methods
body(tag = nil, encoding = nil)
click to toggle source
# File lib/rss2mail/rss.rb 126 def body(tag = nil, encoding = nil) 127 @body ||= get_body(tag, encoding) 128 end
date()
click to toggle source
# File lib/rss2mail/rss.rb 116 def date 117 @date ||= value_for({ date: %w[pubDate updated dc_date] }, :content) { |field, value| 118 field == 'updated' && value.respond_to?(:content) ? Time.at(value.content.to_i) : value 119 } 120 end
description(unescape_html = false)
click to toggle source
# File lib/rss2mail/rss.rb 112 def description(unescape_html = false) 113 @description ||= get_description(unescape_html) 114 end
link()
click to toggle source
# File lib/rss2mail/rss.rb 106 def link 107 @link ||= value_for([:links, :link], :href) { |field, value| 108 field == :links ? value.find { |link| link.rel == 'alternate' } : value 109 } 110 end
subject()
click to toggle source
# File lib/rss2mail/rss.rb 130 def subject 131 @subject ||= title ? clean_subject(title.dup) : 'NO TITLE' 132 end
title()
click to toggle source
# File lib/rss2mail/rss.rb 102 def title 103 @title ||= value_for(:title, :content) 104 end
Private Instance Methods
clean_subject(str)
click to toggle source
# File lib/rss2mail/rss.rb 197 def clean_subject(str) 198 str.replace_diacritics! 199 str.gsub!(SUB_RE, SUB) 200 str.to_ascii 201 end
extract_body(expr, attribute = nil)
click to toggle source
# File lib/rss2mail/rss.rb 192 def extract_body(expr, attribute = nil) 193 load_feed(link) { |doc| elem = doc.at(expr) 194 attribute ? elem[attribute] : elem.to_s } 195 end
get_body(tag, encoding)
click to toggle source
# File lib/rss2mail/rss.rb 175 def get_body(tag, encoding) 176 body = case tag 177 when nil then # nothing 178 when true then open_feed(link).read 179 when String then extract_body(tag) 180 when Array then extract_body(*tag) 181 else raise ArgumentError, "don't know how to handle tag of type #{tag.class}" 182 end or return 183 184 body.gsub!(/<\/?(.*?)>/) { |m| m if KEEP.include?($1.split.first.downcase) } 185 body.gsub!(/<a\s+href=['"](?!http:).*?>(.*?)<\/a>/mi, '\1') 186 187 body.encode!(encoding) if encoding 188 body 189 rescue OpenURI::HTTPError, EOFError, SocketError 190 end
get_description(unescape_html)
click to toggle source
# File lib/rss2mail/rss.rb 164 def get_description(unescape_html) 165 description = value_for({ description: %w[summary content] }, :content) 166 167 if description && unescape_html 168 description.gsub!(/</, '<') 169 description.gsub!(/>/, '>') 170 end 171 172 description 173 end
get_value_for(fields, &block)
click to toggle source
# File lib/rss2mail/rss.rb 149 def get_value_for(fields, &block) 150 fields = fields.is_a?(Hash) ? fields.to_a.flatten : [*fields] 151 152 fields.each { |field| 153 begin 154 value = @item.send(field) 155 value = block[field, value] if block 156 return value if value 157 rescue NoMethodError 158 end 159 } 160 161 nil 162 end
value_for(field, methods = nil, &block)
click to toggle source
# File lib/rss2mail/rss.rb 136 def value_for(field, methods = nil, &block) 137 value = get_value_for(field, &block) 138 139 if methods 140 [*methods].each { |method| 141 break unless value.respond_to?(method) 142 value = value.send(method) 143 } 144 end 145 146 value.respond_to?(:strip) ? value.strip : value 147 end