Class: Blogpostify::Blog
- Inherits:
-
Object
- Object
- Blogpostify::Blog
- Defined in:
- lib/blogpostify/blog.rb
Instance Attribute Summary collapse
-
#homepage ⇒ Object
Returns the value of attribute homepage.
-
#icon ⇒ Object
Returns the value of attribute icon.
-
#short_name ⇒ Object
Returns the value of attribute short_name.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(title, url, options = {}) ⇒ Blog
constructor
A new instance of Blog.
- #populated? ⇒ Boolean
- #posts ⇒ Object
- #update_posts ⇒ Object
Constructor Details
#initialize(title, url, options = {}) ⇒ Blog
Returns a new instance of Blog.
6 7 8 9 10 11 12 |
# File 'lib/blogpostify/blog.rb', line 6 def initialize(title, url, ={}) self.title = title self.url = url self.short_name = [:short_name] self.icon = [:icon] self.homepage = [:homepage] end |
Instance Attribute Details
#homepage ⇒ Object
Returns the value of attribute homepage.
4 5 6 |
# File 'lib/blogpostify/blog.rb', line 4 def homepage @homepage end |
#icon ⇒ Object
Returns the value of attribute icon.
4 5 6 |
# File 'lib/blogpostify/blog.rb', line 4 def icon @icon end |
#short_name ⇒ Object
Returns the value of attribute short_name.
4 5 6 |
# File 'lib/blogpostify/blog.rb', line 4 def short_name @short_name end |
#title ⇒ Object
Returns the value of attribute title.
4 5 6 |
# File 'lib/blogpostify/blog.rb', line 4 def title @title end |
#url ⇒ Object
Returns the value of attribute url.
4 5 6 |
# File 'lib/blogpostify/blog.rb', line 4 def url @url end |
Instance Method Details
#populated? ⇒ Boolean
34 35 36 |
# File 'lib/blogpostify/blog.rb', line 34 def populated? posts.exists? end |
#posts ⇒ Object
30 31 32 |
# File 'lib/blogpostify/blog.rb', line 30 def posts Post.where(:blog_id => self.short_name).asc end |
#update_posts ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/blogpostify/blog.rb', line 14 def update_posts created = [] open(self.url) do |body| rss = RSS::Parser.parse(body) rss.items.each do |post| post = Post.create_from_item(self.short_name, post) # Post not saved if guid is already registered for this blog created << post if post.persisted? end created end end |