Class: Retter::Entry::Article

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#bodyObject

Returns the value of attribute body.



8
9
10
# File 'lib/retter/entry.rb', line 8

def body
  @body
end

#entryObject

Returns the value of attribute entry.



8
9
10
# File 'lib/retter/entry.rb', line 8

def entry
  @entry
end

#idObject

Returns the value of attribute id.



8
9
10
# File 'lib/retter/entry.rb', line 8

def id
  @id
end

#titleObject

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

Returns:

  • (Boolean)


17
18
19
# File 'lib/retter/entry.rb', line 17

def actual?
  @actual
end

#articlesObject



37
38
39
# File 'lib/retter/entry.rb', line 37

def articles
  @articles ||= entry.articles
end

#indexObject



33
34
35
# File 'lib/retter/entry.rb', line 33

def index
  articles.index(self).to_i
end

#nextObject



25
26
27
# File 'lib/retter/entry.rb', line 25

def next
  articles[index.next] || (entry.next && entry.next.articles.first)
end

#prevObject



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 = tags_stripped_body[0, length]

  tags_stripped_body.length > length ? "#{snip}..." : snip
end

#tags_stripped_bodyObject



47
48
49
# File 'lib/retter/entry.rb', line 47

def tags_stripped_body
  @tags_stripped_body ||= body.gsub(/<\/?\s?[^>]+>/, '')
end

#to_sObject



21
22
23
# File 'lib/retter/entry.rb', line 21

def to_s
  body
end