lib/nin/item.rb in nin-1.0.1 vs lib/nin/item.rb in nin-1.2.0

- old
+ new

@@ -1,30 +1,33 @@ module Nin class Item - attr_accessor :id, :desc, :date, :tags, :completed, :archived + attr_accessor :id, :desc, :date, :tags, :uid, :completed, :archived def initialize(id, desc, date = Date.today, tags = [], + uid = nil, completed = false, archived = false, formatter = Presenter::ItemPresenter) @id = id @desc = desc @date = Date.parse_or_return(date) || Date.today - @tags = tags + @tags = tags.ensure_array + @uid = uid @completed = completed @archived = archived @formatter = formatter.new(self) end - def edit(desc, date = nil, tags = []) + def edit(desc, date = nil, tags = [], completed = nil) self.desc = desc - self.date = date unless date.nil? - self.tags.concat(tags) + self.date = Date.parse_or_return(date) unless date.nil? + self.tags.concat(tags.ensure_array).uniq! + self.completed = completed.nil? ? self.completed : completed end def toggle_completed! @completed = !@completed end @@ -57,10 +60,11 @@ { 'id' => id, 'desc' => desc, 'tags' => tags, 'completed' => completed, - 'archived' => archived + 'archived' => archived, + 'uid' => uid } end end end