Class: Retter::Entry

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

Defined Under Namespace

Classes: Article

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Entry

Returns a new instance of Entry.



55
56
57
58
59
60
61
62
63
# File 'lib/retter/entry.rb', line 55

def initialize(attrs = {})
  @entries, @date, @body = attrs.values_at(:entries, :date, :body)

  path_by_date = Entries.retters_dir.join(date.strftime('%Y%m%d.md'))
  @path = attrs[:path] || path_by_date

  extract_articles
  assign_lede
end

Instance Attribute Details

#articlesObject

Returns the value of attribute articles.



52
53
54
# File 'lib/retter/entry.rb', line 52

def articles
  @articles
end

#bodyObject

Returns the value of attribute body.



52
53
54
# File 'lib/retter/entry.rb', line 52

def body
  @body
end

#dateObject

Returns the value of attribute date.



52
53
54
# File 'lib/retter/entry.rb', line 52

def date
  @date
end

#ledeObject

Returns the value of attribute lede.



52
53
54
# File 'lib/retter/entry.rb', line 52

def lede
  @lede
end

#pathObject (readonly)

Returns the value of attribute path.



53
54
55
# File 'lib/retter/entry.rb', line 53

def path
  @path
end

Instance Method Details

#indexObject



77
78
79
# File 'lib/retter/entry.rb', line 77

def index
  @entries.index(self) || 0
end

#nextObject



69
70
71
# File 'lib/retter/entry.rb', line 69

def next
  @entries[index.next]
end

#prevObject



73
74
75
# File 'lib/retter/entry.rb', line 73

def prev
  @entries[index.pred] unless index.pred < 0
end

#to_articleObject



81
82
83
# File 'lib/retter/entry.rb', line 81

def to_article
  Article.new(entry: self, id: 'a0', title: date.to_s, body: body, actual: false)
end

#to_sObject



65
66
67
# File 'lib/retter/entry.rb', line 65

def to_s
  body
end