Class: Trello::Checklist
Overview
A Checklist holds items which are like a “task” list. Checklists are linked to a card.
Instance Attribute Summary collapse
-
#board_id ⇒ String
readonly
A 24-character hex string.
- #card_id ⇒ String
- #check_items ⇒ Object readonly
- #id ⇒ String readonly
- #name ⇒ String
- #position ⇒ Object
- #source_checklist_id ⇒ String writeonly
Attributes inherited from BasicData
Instance Method Summary collapse
-
#add_item(name, checked = false, position = 'bottom') ⇒ Object
Add an item to the checklist.
-
#copy ⇒ Object
Copy a checklist (i.e., same attributes, items, etc.).
-
#delete ⇒ Object
Delete a checklist.
-
#delete_checklist_item(item_id) ⇒ Object
Delete a checklist item.
-
#items ⇒ Object
Return a list of items on the checklist.
-
#update_item_state(item_id, state) ⇒ Object
Update a checklist item’s state, e.g.: “complete” or “incomplete”.
Methods inherited from BasicData
#==, #attributes, client, #collection_name, #collection_path, create, #element_name, #element_path, find, #hash, #initialize, many, one, parse, parse_many, path_name, #refresh!, register_attrs, #save, save, schema, #schema, #update!, #update_fields
Methods included from JsonUtils
Constructor Details
This class inherits a constructor from Trello::BasicData
Instance Attribute Details
#board_id ⇒ String (readonly)
Returns A 24-character hex string.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/trello/checklist.rb', line 18 class Checklist < BasicData schema do attribute :id, readonly: true, primary_key: true # Readonly attribute :check_items, readonly: true, remote_key: 'checkItems' attribute :board_id, readonly: true, remote_key: 'idBoard' # Writable attribute :name attribute :position, remote_key: 'pos' # Writable but for update only attribute :card_id, create_only: true, remote_key: 'idCard' attribute :source_checklist_id, create_only: true, remote_key: 'idChecklistSource' end validates_presence_of :id validates_length_of :name, in: 1..16384 # Return a list of items on the checklist. def items check_items.map do |item_fields| Item.new(item_fields) end end # Return a reference to the board the checklist is on. one :board, path: :checklists, using: :board_id # Return a reference to the card the checklist is on. one :card, path: :checklists, using: :card_id # Add an item to the checklist def add_item(name, checked = false, position = 'bottom') client.post("/checklists/#{id}/checkItems", {name: name, checked: checked, pos: position}) end # Update a checklist item's state, e.g.: "complete" or "incomplete" def update_item_state(item_id, state) state = ( state ? 'complete' : 'incomplete' ) unless state.is_a?(String) client.put( "/cards/#{card_id}/checkItem/#{item_id}", state: state ) end # Delete a checklist item def delete_checklist_item(item_id) client.delete("/checklists/#{id}/checkItems/#{item_id}") end # Delete a checklist def delete client.delete("/checklists/#{id}") end # Copy a checklist (i.e., same attributes, items, etc.) def copy checklist_copy = self.class.create(name: self.name, board_id: self.board_id, card_id: self.card_id) copy_items_to(checklist_copy) return checklist_copy end private def copy_items_to(another_checklist) items.each do |item| another_checklist.add_item(item.name, item.complete?) end end end |
#card_id ⇒ String
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/trello/checklist.rb', line 18 class Checklist < BasicData schema do attribute :id, readonly: true, primary_key: true # Readonly attribute :check_items, readonly: true, remote_key: 'checkItems' attribute :board_id, readonly: true, remote_key: 'idBoard' # Writable attribute :name attribute :position, remote_key: 'pos' # Writable but for update only attribute :card_id, create_only: true, remote_key: 'idCard' attribute :source_checklist_id, create_only: true, remote_key: 'idChecklistSource' end validates_presence_of :id validates_length_of :name, in: 1..16384 # Return a list of items on the checklist. def items check_items.map do |item_fields| Item.new(item_fields) end end # Return a reference to the board the checklist is on. one :board, path: :checklists, using: :board_id # Return a reference to the card the checklist is on. one :card, path: :checklists, using: :card_id # Add an item to the checklist def add_item(name, checked = false, position = 'bottom') client.post("/checklists/#{id}/checkItems", {name: name, checked: checked, pos: position}) end # Update a checklist item's state, e.g.: "complete" or "incomplete" def update_item_state(item_id, state) state = ( state ? 'complete' : 'incomplete' ) unless state.is_a?(String) client.put( "/cards/#{card_id}/checkItem/#{item_id}", state: state ) end # Delete a checklist item def delete_checklist_item(item_id) client.delete("/checklists/#{id}/checkItems/#{item_id}") end # Delete a checklist def delete client.delete("/checklists/#{id}") end # Copy a checklist (i.e., same attributes, items, etc.) def copy checklist_copy = self.class.create(name: self.name, board_id: self.board_id, card_id: self.card_id) copy_items_to(checklist_copy) return checklist_copy end private def copy_items_to(another_checklist) items.each do |item| another_checklist.add_item(item.name, item.complete?) end end end |
#check_items ⇒ Object (readonly)
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/trello/checklist.rb', line 18 class Checklist < BasicData schema do attribute :id, readonly: true, primary_key: true # Readonly attribute :check_items, readonly: true, remote_key: 'checkItems' attribute :board_id, readonly: true, remote_key: 'idBoard' # Writable attribute :name attribute :position, remote_key: 'pos' # Writable but for update only attribute :card_id, create_only: true, remote_key: 'idCard' attribute :source_checklist_id, create_only: true, remote_key: 'idChecklistSource' end validates_presence_of :id validates_length_of :name, in: 1..16384 # Return a list of items on the checklist. def items check_items.map do |item_fields| Item.new(item_fields) end end # Return a reference to the board the checklist is on. one :board, path: :checklists, using: :board_id # Return a reference to the card the checklist is on. one :card, path: :checklists, using: :card_id # Add an item to the checklist def add_item(name, checked = false, position = 'bottom') client.post("/checklists/#{id}/checkItems", {name: name, checked: checked, pos: position}) end # Update a checklist item's state, e.g.: "complete" or "incomplete" def update_item_state(item_id, state) state = ( state ? 'complete' : 'incomplete' ) unless state.is_a?(String) client.put( "/cards/#{card_id}/checkItem/#{item_id}", state: state ) end # Delete a checklist item def delete_checklist_item(item_id) client.delete("/checklists/#{id}/checkItems/#{item_id}") end # Delete a checklist def delete client.delete("/checklists/#{id}") end # Copy a checklist (i.e., same attributes, items, etc.) def copy checklist_copy = self.class.create(name: self.name, board_id: self.board_id, card_id: self.card_id) copy_items_to(checklist_copy) return checklist_copy end private def copy_items_to(another_checklist) items.each do |item| another_checklist.add_item(item.name, item.complete?) end end end |
#id ⇒ String (readonly)
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/trello/checklist.rb', line 18 class Checklist < BasicData schema do attribute :id, readonly: true, primary_key: true # Readonly attribute :check_items, readonly: true, remote_key: 'checkItems' attribute :board_id, readonly: true, remote_key: 'idBoard' # Writable attribute :name attribute :position, remote_key: 'pos' # Writable but for update only attribute :card_id, create_only: true, remote_key: 'idCard' attribute :source_checklist_id, create_only: true, remote_key: 'idChecklistSource' end validates_presence_of :id validates_length_of :name, in: 1..16384 # Return a list of items on the checklist. def items check_items.map do |item_fields| Item.new(item_fields) end end # Return a reference to the board the checklist is on. one :board, path: :checklists, using: :board_id # Return a reference to the card the checklist is on. one :card, path: :checklists, using: :card_id # Add an item to the checklist def add_item(name, checked = false, position = 'bottom') client.post("/checklists/#{id}/checkItems", {name: name, checked: checked, pos: position}) end # Update a checklist item's state, e.g.: "complete" or "incomplete" def update_item_state(item_id, state) state = ( state ? 'complete' : 'incomplete' ) unless state.is_a?(String) client.put( "/cards/#{card_id}/checkItem/#{item_id}", state: state ) end # Delete a checklist item def delete_checklist_item(item_id) client.delete("/checklists/#{id}/checkItems/#{item_id}") end # Delete a checklist def delete client.delete("/checklists/#{id}") end # Copy a checklist (i.e., same attributes, items, etc.) def copy checklist_copy = self.class.create(name: self.name, board_id: self.board_id, card_id: self.card_id) copy_items_to(checklist_copy) return checklist_copy end private def copy_items_to(another_checklist) items.each do |item| another_checklist.add_item(item.name, item.complete?) end end end |
#name ⇒ String
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/trello/checklist.rb', line 18 class Checklist < BasicData schema do attribute :id, readonly: true, primary_key: true # Readonly attribute :check_items, readonly: true, remote_key: 'checkItems' attribute :board_id, readonly: true, remote_key: 'idBoard' # Writable attribute :name attribute :position, remote_key: 'pos' # Writable but for update only attribute :card_id, create_only: true, remote_key: 'idCard' attribute :source_checklist_id, create_only: true, remote_key: 'idChecklistSource' end validates_presence_of :id validates_length_of :name, in: 1..16384 # Return a list of items on the checklist. def items check_items.map do |item_fields| Item.new(item_fields) end end # Return a reference to the board the checklist is on. one :board, path: :checklists, using: :board_id # Return a reference to the card the checklist is on. one :card, path: :checklists, using: :card_id # Add an item to the checklist def add_item(name, checked = false, position = 'bottom') client.post("/checklists/#{id}/checkItems", {name: name, checked: checked, pos: position}) end # Update a checklist item's state, e.g.: "complete" or "incomplete" def update_item_state(item_id, state) state = ( state ? 'complete' : 'incomplete' ) unless state.is_a?(String) client.put( "/cards/#{card_id}/checkItem/#{item_id}", state: state ) end # Delete a checklist item def delete_checklist_item(item_id) client.delete("/checklists/#{id}/checkItems/#{item_id}") end # Delete a checklist def delete client.delete("/checklists/#{id}") end # Copy a checklist (i.e., same attributes, items, etc.) def copy checklist_copy = self.class.create(name: self.name, board_id: self.board_id, card_id: self.card_id) copy_items_to(checklist_copy) return checklist_copy end private def copy_items_to(another_checklist) items.each do |item| another_checklist.add_item(item.name, item.complete?) end end end |
#position ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/trello/checklist.rb', line 18 class Checklist < BasicData schema do attribute :id, readonly: true, primary_key: true # Readonly attribute :check_items, readonly: true, remote_key: 'checkItems' attribute :board_id, readonly: true, remote_key: 'idBoard' # Writable attribute :name attribute :position, remote_key: 'pos' # Writable but for update only attribute :card_id, create_only: true, remote_key: 'idCard' attribute :source_checklist_id, create_only: true, remote_key: 'idChecklistSource' end validates_presence_of :id validates_length_of :name, in: 1..16384 # Return a list of items on the checklist. def items check_items.map do |item_fields| Item.new(item_fields) end end # Return a reference to the board the checklist is on. one :board, path: :checklists, using: :board_id # Return a reference to the card the checklist is on. one :card, path: :checklists, using: :card_id # Add an item to the checklist def add_item(name, checked = false, position = 'bottom') client.post("/checklists/#{id}/checkItems", {name: name, checked: checked, pos: position}) end # Update a checklist item's state, e.g.: "complete" or "incomplete" def update_item_state(item_id, state) state = ( state ? 'complete' : 'incomplete' ) unless state.is_a?(String) client.put( "/cards/#{card_id}/checkItem/#{item_id}", state: state ) end # Delete a checklist item def delete_checklist_item(item_id) client.delete("/checklists/#{id}/checkItems/#{item_id}") end # Delete a checklist def delete client.delete("/checklists/#{id}") end # Copy a checklist (i.e., same attributes, items, etc.) def copy checklist_copy = self.class.create(name: self.name, board_id: self.board_id, card_id: self.card_id) copy_items_to(checklist_copy) return checklist_copy end private def copy_items_to(another_checklist) items.each do |item| another_checklist.add_item(item.name, item.complete?) end end end |
#source_checklist_id=(value) ⇒ String (writeonly)
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/trello/checklist.rb', line 18 class Checklist < BasicData schema do attribute :id, readonly: true, primary_key: true # Readonly attribute :check_items, readonly: true, remote_key: 'checkItems' attribute :board_id, readonly: true, remote_key: 'idBoard' # Writable attribute :name attribute :position, remote_key: 'pos' # Writable but for update only attribute :card_id, create_only: true, remote_key: 'idCard' attribute :source_checklist_id, create_only: true, remote_key: 'idChecklistSource' end validates_presence_of :id validates_length_of :name, in: 1..16384 # Return a list of items on the checklist. def items check_items.map do |item_fields| Item.new(item_fields) end end # Return a reference to the board the checklist is on. one :board, path: :checklists, using: :board_id # Return a reference to the card the checklist is on. one :card, path: :checklists, using: :card_id # Add an item to the checklist def add_item(name, checked = false, position = 'bottom') client.post("/checklists/#{id}/checkItems", {name: name, checked: checked, pos: position}) end # Update a checklist item's state, e.g.: "complete" or "incomplete" def update_item_state(item_id, state) state = ( state ? 'complete' : 'incomplete' ) unless state.is_a?(String) client.put( "/cards/#{card_id}/checkItem/#{item_id}", state: state ) end # Delete a checklist item def delete_checklist_item(item_id) client.delete("/checklists/#{id}/checkItems/#{item_id}") end # Delete a checklist def delete client.delete("/checklists/#{id}") end # Copy a checklist (i.e., same attributes, items, etc.) def copy checklist_copy = self.class.create(name: self.name, board_id: self.board_id, card_id: self.card_id) copy_items_to(checklist_copy) return checklist_copy end private def copy_items_to(another_checklist) items.each do |item| another_checklist.add_item(item.name, item.complete?) end end end |
Instance Method Details
#add_item(name, checked = false, position = 'bottom') ⇒ Object
Add an item to the checklist
52 53 54 |
# File 'lib/trello/checklist.rb', line 52 def add_item(name, checked = false, position = 'bottom') client.post("/checklists/#{id}/checkItems", {name: name, checked: checked, pos: position}) end |
#copy ⇒ Object
Copy a checklist (i.e., same attributes, items, etc.)
76 77 78 79 80 |
# File 'lib/trello/checklist.rb', line 76 def copy checklist_copy = self.class.create(name: self.name, board_id: self.board_id, card_id: self.card_id) copy_items_to(checklist_copy) return checklist_copy end |
#delete ⇒ Object
Delete a checklist
71 72 73 |
# File 'lib/trello/checklist.rb', line 71 def delete client.delete("/checklists/#{id}") end |
#delete_checklist_item(item_id) ⇒ Object
Delete a checklist item
66 67 68 |
# File 'lib/trello/checklist.rb', line 66 def delete_checklist_item(item_id) client.delete("/checklists/#{id}/checkItems/#{item_id}") end |
#items ⇒ Object
Return a list of items on the checklist.
39 40 41 42 43 |
# File 'lib/trello/checklist.rb', line 39 def items check_items.map do |item_fields| Item.new(item_fields) end end |
#update_item_state(item_id, state) ⇒ Object
Update a checklist item’s state, e.g.: “complete” or “incomplete”
57 58 59 60 61 62 63 |
# File 'lib/trello/checklist.rb', line 57 def update_item_state(item_id, state) state = ( state ? 'complete' : 'incomplete' ) unless state.is_a?(String) client.put( "/cards/#{card_id}/checkItem/#{item_id}", state: state ) end |