class Trello::Checklist
A Checklist
holds items which are like a “task” list. Checklists are linked to a card.
@!attribute [r] id
@return [String]
@!attribute [rw] name
@return [String]
@!attribute [r] description
@return [String]
@!attribute [r] closed
@return [Boolean]
@!attribute [rw] position
@return [Object]
@!attribute [r] url
@return [String]
@!attribute [r] check_items
@return [Object]
@!attribute [r] board_id
@return [String] A 24-character hex string
@!attribute [r] list_id
@return [String] A 24-character hex string
@!attribute [r] member_ids
@return [Array<String>] An array of 24-character hex strings
Public Class Methods
# File lib/trello/checklist.rb, line 36 def create(options) client.create(:checklist, 'name' => options[:name], 'idCard' => options[:card_id]) end
Locate a specific checklist by its id.
# File lib/trello/checklist.rb, line 32 def find(id, params = {}) client.find(:checklist, id, params) end
Public Instance Methods
Add an item to the checklist
# File lib/trello/checklist.rb, line 106 def add_item(name, checked = false, position = 'bottom') client.post("/checklists/#{id}/checkItems", {name: name, checked: checked, pos: position}) end
Check if the checklist is currently active.
# File lib/trello/checklist.rb, line 63 def closed? closed end
Copy a checklist (i.e., same attributes, items, etc.)
# File lib/trello/checklist.rb, line 130 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 a checklist
# File lib/trello/checklist.rb, line 125 def delete client.delete("/checklists/#{id}") end
Delete a checklist item
# File lib/trello/checklist.rb, line 120 def delete_checklist_item(item_id) client.delete("/checklists/#{id}/checkItems/#{item_id}") end
Return a list of items on the checklist.
# File lib/trello/checklist.rb, line 82 def items check_items.map do |item_fields| Item.new(item_fields) end end
Return a list of members active in this checklist.
# File lib/trello/checklist.rb, line 98 def members members = member_ids.map do |member_id| Member.find(member_id) end MultiAssociation.new(self, members).proxy end
Save a record.
# File lib/trello/checklist.rb, line 68 def save return update! if id from_response(client.post("/checklists", { name: name, idCard: card_id })) end
# File lib/trello/checklist.rb, line 77 def update! from_response(client.put("/checklists/#{id}", {name: name, pos: position})) end
Update the fields of a checklist.
Supply a hash of string keyed data retrieved from the Trello
API representing a checklist.
# File lib/trello/checklist.rb, line 47 def update_fields(fields) attributes[:id] = fields['id'] || attributes[:id] attributes[:name] = fields['name'] || fields[:name] || attributes[:name] attributes[:description] = fields['desc'] || attributes[:description] attributes[:closed] = fields['closed'] if fields.has_key?('closed') attributes[:url] = fields['url'] || attributes[:url] attributes[:check_items] = fields['checkItems'] if fields.has_key?('checkItems') attributes[:position] = fields['pos'] || attributes[:position] attributes[:board_id] = fields['idBoard'] || attributes[:board_id] attributes[:card_id] = fields['idCard'] || fields[:card_id] || attributes[:card_id] attributes[:list_id] = fields['idList'] || attributes[:list_id] attributes[:member_ids] = fields['idMembers'] || attributes[:member_ids] self end
Update a checklist item's state, e.g.: “complete” or “incomplete”
# File lib/trello/checklist.rb, line 111 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
Private Instance Methods
# File lib/trello/checklist.rb, line 137 def copy_items_to(another_checklist) items.each do |item| another_checklist.add_item(item.name, item.complete?) end end