Class: Nin::Item
Instance Attribute Summary collapse
-
#archived ⇒ Object
Returns the value of attribute archived.
-
#completed ⇒ Object
Returns the value of attribute completed.
-
#date ⇒ Object
Returns the value of attribute date.
-
#desc ⇒ Object
Returns the value of attribute desc.
-
#id ⇒ Object
Returns the value of attribute id.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#uid ⇒ Object
Returns the value of attribute uid.
Instance Method Summary collapse
- #archived? ⇒ Boolean
- #completed? ⇒ Boolean
- #edit(desc, date = nil, tags = [], completed = nil) ⇒ Object
-
#initialize(id, desc, date = Date.today, tags = [], uid = nil, completed = false, archived = false, formatter = Presenter::ItemPresenter) ⇒ Item
constructor
A new instance of Item.
- #past? ⇒ Boolean
- #to_h ⇒ Object
- #to_s ⇒ Object
- #today? ⇒ Boolean
- #toggle_archived! ⇒ Object
- #toggle_completed! ⇒ Object
Constructor Details
#initialize(id, desc, date = Date.today, tags = [], uid = nil, completed = false, archived = false, formatter = Presenter::ItemPresenter) ⇒ Item
Returns a new instance of Item.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/nin/item.rb', line 5 def initialize(id, desc, date = Date.today, = [], uid = nil, completed = false, archived = false, formatter = Presenter::ItemPresenter) @id = id @desc = desc @date = Date.parse_or_return(date) || Date.today = .ensure_array @uid = uid @completed = completed @archived = archived @formatter = formatter.new(self) end |
Instance Attribute Details
#archived ⇒ Object
Returns the value of attribute archived.
3 4 5 |
# File 'lib/nin/item.rb', line 3 def archived @archived end |
#completed ⇒ Object
Returns the value of attribute completed.
3 4 5 |
# File 'lib/nin/item.rb', line 3 def completed @completed end |
#date ⇒ Object
Returns the value of attribute date.
3 4 5 |
# File 'lib/nin/item.rb', line 3 def date @date end |
#desc ⇒ Object
Returns the value of attribute desc.
3 4 5 |
# File 'lib/nin/item.rb', line 3 def desc @desc end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/nin/item.rb', line 3 def id @id end |
#uid ⇒ Object
Returns the value of attribute uid.
3 4 5 |
# File 'lib/nin/item.rb', line 3 def uid @uid end |
Instance Method Details
#archived? ⇒ Boolean
43 44 45 |
# File 'lib/nin/item.rb', line 43 def archived? @archived end |
#completed? ⇒ Boolean
39 40 41 |
# File 'lib/nin/item.rb', line 39 def completed? @completed end |
#edit(desc, date = nil, tags = [], completed = nil) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/nin/item.rb', line 24 def edit(desc, date = nil, = [], completed = nil) self.desc = desc self.date = Date.parse_or_return(date) unless date.nil? self..concat(.ensure_array).uniq! self.completed = completed.nil? ? self.completed : completed end |
#past? ⇒ Boolean
47 48 49 |
# File 'lib/nin/item.rb', line 47 def past? @date < Date.today end |
#to_h ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/nin/item.rb', line 59 def to_h { 'id' => id, 'desc' => desc, 'tags' => , 'completed' => completed, 'archived' => archived, 'uid' => uid } end |
#to_s ⇒ Object
55 56 57 |
# File 'lib/nin/item.rb', line 55 def to_s @formatter.call end |
#today? ⇒ Boolean
51 52 53 |
# File 'lib/nin/item.rb', line 51 def today? @date == Date.today end |
#toggle_archived! ⇒ Object
35 36 37 |
# File 'lib/nin/item.rb', line 35 def toggle_archived! @archived = !@archived end |
#toggle_completed! ⇒ Object
31 32 33 |
# File 'lib/nin/item.rb', line 31 def toggle_completed! @completed = !@completed end |