class LinkedPosts
Public Class Methods
new(posts)
click to toggle source
# File lib/linked_posts.rb, line 2 def initialize(posts) @posts = posts end
Public Instance Methods
current()
click to toggle source
# File lib/linked_posts.rb, line 10 def current @posts.detect { |p| p.slug == @slug } end
next_post()
click to toggle source
# File lib/linked_posts.rb, line 18 def next_post @posts[current_index - 1] unless current_index == 0 end
previous_post()
click to toggle source
# File lib/linked_posts.rb, line 14 def previous_post @posts[current_index + 1] end
slug=(slug)
click to toggle source
# File lib/linked_posts.rb, line 6 def slug=(slug) @slug = slug end
Private Instance Methods
current_index()
click to toggle source
# File lib/linked_posts.rb, line 24 def current_index @posts.index(current) end