Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Notification < ActiveRecord::Base
- validates_presence_of :feed
- attr_accessor :doc
- after_create :create_posts
- def posts
- entries.map { |entry| entry_format(entry) } if entries
- end
- def create_posts
- Post.create(posts) if posts
- end
- private
- def parse
- @doc ||= Nokogiri::HTML(self.feed)
- end
- def entries
- parse.css('entry') unless dummy?
- end
- def dummy?
- parse.css('feed').css('id').first.text.include?('dummy')
- end
- def entry_format(entry)
- { url: entry.css('id').text, title: entry.css('title').text, body: entry.css('content').text }
- end
- end
Add Comment
Please, Sign In to add comment