Class: Blogpostify::Blog

Inherits:
Object
  • Object
show all
Defined in:
lib/blogpostify/blog.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options={})
  self.title = title
  self.url = url
  self.short_name = options[:short_name]
  self.icon = options[:icon]
  self.homepage = options[:homepage]
end

Instance Attribute Details

#homepageObject

Returns the value of attribute homepage.



4
5
6
# File 'lib/blogpostify/blog.rb', line 4

def homepage
  @homepage
end

#iconObject

Returns the value of attribute icon.



4
5
6
# File 'lib/blogpostify/blog.rb', line 4

def icon
  @icon
end

#short_nameObject

Returns the value of attribute short_name.



4
5
6
# File 'lib/blogpostify/blog.rb', line 4

def short_name
  @short_name
end

#titleObject

Returns the value of attribute title.



4
5
6
# File 'lib/blogpostify/blog.rb', line 4

def title
  @title
end

#urlObject

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

Returns:

  • (Boolean)


34
35
36
# File 'lib/blogpostify/blog.rb', line 34

def populated?
  posts.exists?
end

#postsObject



30
31
32
# File 'lib/blogpostify/blog.rb', line 30

def posts
  Post.where(:blog_id => self.short_name).asc
end

#update_postsObject



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