PageRenderTime 32ms CodeModel.GetById 22ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/tools/parser/lib/parser/globo_esporte.rb

https://bitbucket.org/tbueno/planetafutebol
Ruby | 44 lines | 31 code | 13 blank | 0 comment | 1 complexity | 304360ed5e8f41f26b487b3ddd12aaf8 MD5 | raw file
 1require 'open-uri'
 2require 'action_view'
 3
 4module Parser    
 5    class GloboEsporteEntry < Feedzirra::Parser::RSSEntry
 6      include ActionView::Helpers::SanitizeHelper 
 7      include SAXMachine
 8      include Feedzirra::FeedEntryUtilities
 9
10      def content
11        return @content if @content
12        page = Nokogiri::HTML(open(url)).css('div#materia-letra').first
13        @content = page.inner_html ? sanitize(page.inner_html, :attributes => %w(alt src title href)) : ''
14      end
15
16      def summary
17        sanitize @summary, :tags => %w(p)
18      end
19
20      def author
21        'globoesporte.com'
22      end
23    end
24
25
26
27    class GloboEsporte 
28      include SAXMachine
29      include Feedzirra::FeedUtilities
30
31      element :title
32
33      element :link, :as => :url
34      elements :item , :as => :entries, :class => GloboEsporteEntry
35
36      attr_accessor :feed_url
37
38      def self.able_to_parse?(xml)
39         (/globoesporte.globo.com/ =~ xml)
40      end
41
42    end
43end
44