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

create(options) click to toggle source
# File lib/trello/checklist.rb, line 36
def create(options)
  client.create(:checklist,
                'name' => options[:name],
                'idCard'  => options[:card_id])
end
find(id, params = {}) click to toggle source

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_item(name, checked = false, position = 'bottom') click to toggle source

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
closed?() click to toggle source

Check if the checklist is currently active.

# File lib/trello/checklist.rb, line 63
def closed?
  closed
end
copy() click to toggle source

Copy a checklist (i.e., same attributes, items, etc.)

# File lib/trello/checklist.rb, line 129
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() click to toggle source

Delete a checklist

# File lib/trello/checklist.rb, line 124
def delete
  client.delete("/checklists/#{id}")
end
delete_checklist_item(item_id) click to toggle source

Delete a checklist item

# File lib/trello/checklist.rb, line 119
def delete_checklist_item(item_id)
  client.delete("/checklists/#{id}/checkItems/#{item_id}")
end
items() click to toggle source

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
members() click to toggle source

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() click to toggle source

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
update!() click to toggle source
# File lib/trello/checklist.rb, line 77
def update!
  from_response(client.put("/checklists/#{id}", {name: name, pos: position}))
end
update_fields(fields) click to toggle source

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[:name] = fields['name'] || fields[:name]
  attributes[:description] = fields['desc']
  attributes[:closed] = fields['closed']
  attributes[:url] = fields['url']
  attributes[:check_items] = fields['checkItems']
  attributes[:position] = fields['pos']
  attributes[:board_id] = fields['idBoard']
  attributes[:card_id] = fields['idCard'] || fields[:card_id]
  attributes[:list_id] = fields['idList']
  attributes[:member_ids] = fields['idMembers']
  self
end
update_item_state(item_id, state) click to toggle source

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)
  client.put(
    "/cards/#{card_id}/checklist/#{id}/checkItem/#{item_id}/state",
    value: state,
  )
end

Private Instance Methods

copy_items_to(another_checklist) click to toggle source
# File lib/trello/checklist.rb, line 136
def copy_items_to(another_checklist)
  items.each do |item|
    another_checklist.add_item(item.name, item.complete?)
  end
end