Class: Todoable::Item

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

Overview

Class that represents TODO Items

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(todoable, list, params) ⇒ Item

Create instances of the Item class

Parameters:

  • todoable (Todoable::Todoable)

    Instance of the `Todoable` class that knows how to perform authenticated requests.

  • list (Todoable::List)

    instance of the list this new TODO item will belong to

  • params (Hash)

    The parameters of the item. The hash must contain the fields `name`, `id`, and `finished_at`.



96
97
98
99
100
101
102
# File 'lib/todoable.rb', line 96

def initialize todoable, list, params
  @todoable = todoable
  @list = list
  @name = params['name']
  @id = params['id']
  @finished_at = params['finished_at']
end

Instance Attribute Details

#finished_atObject

Returns the value of attribute finished_at



84
85
86
# File 'lib/todoable.rb', line 84

def finished_at
  @finished_at
end

#idObject

Returns the value of attribute id



83
84
85
# File 'lib/todoable.rb', line 83

def id
  @id
end

#nameObject

Returns the value of attribute name



82
83
84
# File 'lib/todoable.rb', line 82

def name
  @name
end

Instance Method Details

#deleteObject

Delete the TODO item from the list



111
112
113
114
# File 'lib/todoable.rb', line 111

def delete
  params = {:list_id => @list.id, :item_id => @id}
  @todoable.request!("delete", ITEM_PATH, params)
end

#mark_finishedObject

Marks the TODO item as finished



105
106
107
108
# File 'lib/todoable.rb', line 105

def mark_finished
  params = {:list_id => @list.id, :item_id => @id}
  @todoable.request!("put", ITEM_FINISHED_PATH, params)
end