Class: Ausca::RSS::Util

Inherits:
Object
  • Object
show all
Defined in:
lib/ausca/rss/util.rb

Class Method Summary collapse

Class Method Details

.default_text(item) ⇒ Object



21
22
23
24
25
# File 'lib/ausca/rss/util.rb', line 21

def default_text item
  s = "#{item[:title]} #{item[:link]}"
  s += " ##{item[:category].gsub(/\s+/, "").downcase}" if item[:category]
  CGI::unescape_html s #.html_safe
end

.default_text_with_description(item) ⇒ Object



27
28
29
30
31
# File 'lib/ausca/rss/util.rb', line 27

def default_text_with_description item
  s = "#{item[:title]}: #{item[:description]} #{item[:link]}"
  s += " ##{item[:category].gsub(/\s+/, "").downcase}" if item[:category]
  CGI::unescape_html s #.html_safe
end

.item_image_url(item) ⇒ Object

Get an image from the image or content element



14
15
16
17
18
19
# File 'lib/ausca/rss/util.rb', line 14

def item_image_url item
  url = i.at_xpath('media|thumbnail').attr('url') if i.at_xpath('media|thumbnail') rescue nil
  url = i.at_xpath('enclosure').attr('url') unless url rescue nil
  #url = item.content.to_s[/img.*?src=\\\"(.*?)\\\"/i,1] unless url rescue nil
  url 
end

.item_source_url(node) ⇒ Object

Get the source URL for an RSS item



7
8
9
10
11
# File 'lib/ausca/rss/util.rb', line 7

def item_source_url node
  url = node.at_xpath('source').attr('url') if node.at_xpath('source')
  url = (node.xpath('link').text if node.at_xpath('link')) unless url         
  url
end