Module: Automatic::FeedParser
- Defined in:
- lib/automatic/feed_parser.rb
Class Method Summary collapse
Class Method Details
.create(feeds = []) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/automatic/feed_parser.rb', line 30 def self.create(feeds = []) RSS::Maker.make("2.0") {|maker| xss = maker.xml_stylesheets.new_xml_stylesheet maker.channel.title = "Automatic Ruby" maker.channel.description = "Automatic Ruby" maker.channel.link = "https://github.com/id774/automaticruby" maker.items.do_sort = true unless feeds.nil? feeds.each {|feed| unless feed.link.nil? Automatic::Log.puts("info", "Creating: #{feed.link}") item = maker.items.new_item item.title = feed.title item.link = feed.link begin item.description = feed.description item. = feed. item.comments = feed.comments item.date = feed.pubDate || Time.now rescue NoMethodError Automatic::Log.puts("warn", "Undefined field detected in feed.") end end } end } end |
.get(url) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/automatic/feed_parser.rb', line 15 def self.get(url) begin unless url.nil? Automatic::Log.puts("info", "Parsing: #{url}") feed = URI.parse(url).normalize open(feed) {|http| response = http.read RSS::Parser.parse(response, false) } end rescue => e raise e end end |
.parse(html) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/automatic/feed_parser.rb', line 59 def self.parse(html) RSS::Maker.make("2.0") {|maker| xss = maker.xml_stylesheets.new_xml_stylesheet maker.channel.title = "Automatic Ruby" maker.channel.description = "Automatic Ruby" maker.channel.link = "https://github.com/id774/automaticruby" maker.items.do_sort = true doc = Nokogiri::HTML(html) (doc/:a).each {|link| unless link[:href].nil? item = maker.items.new_item item.title = "Automatic Ruby" item.link = link[:href] item.date = Time.now item.description = "" end } } end |