Class: LinkedPosts
- Inherits:
-
Object
- Object
- LinkedPosts
- Defined in:
- lib/linked_posts.rb
Instance Method Summary collapse
- #current ⇒ Object
-
#initialize(posts) ⇒ LinkedPosts
constructor
A new instance of LinkedPosts.
- #next_post ⇒ Object
- #previous_post ⇒ Object
- #slug=(slug) ⇒ Object
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
#current ⇒ Object
10 11 12 |
# File 'lib/linked_posts.rb', line 10 def current @posts.detect { |p| p.slug == @slug } end |
#next_post ⇒ Object
18 19 20 |
# File 'lib/linked_posts.rb', line 18 def next_post @posts[current_index - 1] unless current_index == 0 end |
#previous_post ⇒ Object
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 |