Class: Retter::Entry::Article
- Inherits:
-
Object
- Object
- Retter::Entry::Article
- Defined in:
- lib/retter/entry.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#entry ⇒ Object
Returns the value of attribute entry.
-
#id ⇒ Object
Returns the value of attribute id.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
-
#actual? ⇒ Boolean
XXX return false if generated by Entry#to_article.
- #articles ⇒ Object
- #index ⇒ Object
-
#initialize(attrs = {}) ⇒ Article
constructor
A new instance of Article.
- #next ⇒ Object
- #prev ⇒ Object
- #snippet(length = 200) ⇒ Object
- #tags_stripped_body ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ Article
Returns a new instance of Article.
10 11 12 13 14 |
# File 'lib/retter/entry.rb', line 10 def initialize(attrs = {}) attrs = {actual: true}.merge(attrs) @id, @entry, @title, @body, @actual = attrs.values_at(:id, :entry, :title, :body, :actual) end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
8 9 10 |
# File 'lib/retter/entry.rb', line 8 def body @body end |
#entry ⇒ Object
Returns the value of attribute entry.
8 9 10 |
# File 'lib/retter/entry.rb', line 8 def entry @entry end |
#id ⇒ Object
Returns the value of attribute id.
8 9 10 |
# File 'lib/retter/entry.rb', line 8 def id @id end |
#title ⇒ Object
Returns the value of attribute title.
8 9 10 |
# File 'lib/retter/entry.rb', line 8 def title @title end |
Instance Method Details
#actual? ⇒ Boolean
XXX return false if generated by Entry#to_article
17 18 19 |
# File 'lib/retter/entry.rb', line 17 def actual? @actual end |
#articles ⇒ Object
37 38 39 |
# File 'lib/retter/entry.rb', line 37 def articles @articles ||= entry.articles end |
#index ⇒ Object
33 34 35 |
# File 'lib/retter/entry.rb', line 33 def index articles.index(self).to_i end |
#next ⇒ Object
25 26 27 |
# File 'lib/retter/entry.rb', line 25 def next articles[index.next] || (entry.next && entry.next.articles.first) end |
#prev ⇒ Object
29 30 31 |
# File 'lib/retter/entry.rb', line 29 def prev index.pred < 0 ? (entry.prev && entry.prev.articles.last) : articles[index.pred] end |
#snippet(length = 200) ⇒ Object
41 42 43 44 45 |
# File 'lib/retter/entry.rb', line 41 def snippet(length = 200) snip = [0, length] .length > length ? "#{snip}..." : snip end |
#tags_stripped_body ⇒ Object
47 48 49 |
# File 'lib/retter/entry.rb', line 47 def @tags_stripped_body ||= body.gsub(/<\/?\s?[^>]+>/, '') end |
#to_s ⇒ Object
21 22 23 |
# File 'lib/retter/entry.rb', line 21 def to_s body end |