Class: Woli::DiaryEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/woli/diary_entry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date, text, repository) ⇒ DiaryEntry

Returns a new instance of DiaryEntry.



6
7
8
9
10
# File 'lib/woli/diary_entry.rb', line 6

def initialize(date, text, repository)
  @date = date
  @text = text
  @repository = repository
end

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date.



3
4
5
# File 'lib/woli/diary_entry.rb', line 3

def date
  @date
end

#repositoryObject (readonly)

Returns the value of attribute repository.



3
4
5
# File 'lib/woli/diary_entry.rb', line 3

def repository
  @repository
end

#textObject

Returns the value of attribute text.



4
5
6
# File 'lib/woli/diary_entry.rb', line 4

def text
  @text
end

Instance Method Details

#persistObject



12
13
14
15
16
17
18
19
# File 'lib/woli/diary_entry.rb', line 12

def persist
  if text.strip.length > 0
    repository.save_entry(self)
  else
    puts "Empty entry -- removing."
    repository.delete_entry(self)
  end
end