lib/nin/item.rb in nin-0.7.0 vs lib/nin/item.rb in nin-1.0.0
- old
+ new
@@ -2,59 +2,65 @@
class Item
attr_accessor :id, :desc, :date, :tags, :completed, :archived
def initialize(id,
desc,
- date = nil,
+ date = Date.today,
tags = [],
completed = false,
archived = false,
- formatter = ItemPresenter)
+ formatter = Presenter::ItemPresenter)
@id = id
@desc = desc
- self.date = date # this looks ugly
+ @date = Date.parse_or_return(date) || Date.today
@tags = tags
@completed = completed
@archived = archived
@formatter = formatter.new(self)
end
- def date=(date = nil)
- @date = date || Date.today.to_s
+ def edit(desc, date = nil, tags = [])
+ self.desc = desc
+ self.date = date unless date.nil?
+ self.tags.concat(tags)
end
def toggle_completed!
@completed = !@completed
end
def toggle_archived!
@archived = !@archived
end
+ def completed?
+ @completed
+ end
+
+ def archived?
+ @archived
+ end
+
+ def past?
+ @date < Date.today
+ end
+
+ def today?
+ @date == Date.today
+ end
+
def to_s
@formatter.call
end
def to_h
{
'id' => id,
'desc' => desc,
'tags' => tags,
'completed' => completed,
- 'archived' => archived
+ 'archived' => archived
}
- end
-
- def completed?
- @completed
- end
-
- def archived?
- @archived
- end
-
- def due?
- @date < Date.today.to_s
end
end
end