Class: LinkedPosts

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

Instance Method Summary collapse

Constructor Details

#initialize(posts) ⇒ LinkedPosts

Returns a new instance of LinkedPosts.



2
3
4
# File 'lib/linked_posts.rb', line 2

def initialize(posts)
  @posts = posts
end

Instance Method Details

#currentObject



10
11
12
# File 'lib/linked_posts.rb', line 10

def current
  @posts.detect { |p| p.slug == @slug }
end

#next_postObject



18
19
20
# File 'lib/linked_posts.rb', line 18

def next_post
  @posts[current_index - 1] unless current_index == 0
end

#previous_postObject



14
15
16
# File 'lib/linked_posts.rb', line 14

def previous_post
  @posts[current_index + 1]
end

#slug=(slug) ⇒ Object



6
7
8
# File 'lib/linked_posts.rb', line 6

def slug=(slug)
  @slug = slug
end