Class: BlogGenerator::PostList

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/blog-generator/post_list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site, posts = Array.new) ⇒ PostList

Returns a new instance of PostList.



9
10
11
# File 'lib/blog-generator/post_list.rb', line 9

def initialize(site, posts = Array.new)
  @site, @posts = site, posts
end

Instance Attribute Details

#postsObject (readonly)

Returns the value of attribute posts.



8
9
10
# File 'lib/blog-generator/post_list.rb', line 8

def posts
  @posts
end

#siteObject (readonly)

Returns the value of attribute site.



8
9
10
# File 'lib/blog-generator/post_list.rb', line 8

def site
  @site
end

Instance Method Details

#as_jsonObject



15
16
17
18
19
20
21
# File 'lib/blog-generator/post_list.rb', line 15

def as_json
  self.posts.map do |post|
    post.as_json.tap do ||
      .delete(:body)
    end
  end
end

#to_json(*args) ⇒ Object



23
24
25
# File 'lib/blog-generator/post_list.rb', line 23

def to_json(*args)
  self.as_json.to_json(*args)
end