Class: Trello::Checklist

Inherits:
BasicData show all
Defined in:
lib/trello/checklist.rb

Overview

A Checklist holds items which are like a “task” list. Checklists are linked to a card.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BasicData

#==, #initialize, many, one, #refresh!, register_attributes

Constructor Details

This class inherits a constructor from Trello::BasicData

Class Method Details

.create(options) ⇒ Object



15
16
17
18
# File 'lib/trello/checklist.rb', line 15

def create(options)
  new('name'       => options[:name],
      'idBoard'    => options[:board_id]).save
end

.find(id) ⇒ Object

Locate a specific checklist by its id.



11
12
13
# File 'lib/trello/checklist.rb', line 11

def find(id)
  super(:checklists, id)
end

Instance Method Details

#add_item(name) ⇒ Object

Add an item to the checklist



78
79
80
# File 'lib/trello/checklist.rb', line 78

def add_item(name)
  Client.post("/checklists/#{id}/checkItems", { :name => name })
end

#closed?Boolean

Check if the checklist is currently active.

Returns:

  • (Boolean)


38
39
40
# File 'lib/trello/checklist.rb', line 38

def closed?
  closed
end

#itemsObject

Return a list of items on the checklist.



57
58
59
60
61
# File 'lib/trello/checklist.rb', line 57

def items
  check_items.map do |item_fields|
    Item.new(item_fields)
  end
end

#membersObject

Return a list of members active in this checklist.



70
71
72
73
74
75
# File 'lib/trello/checklist.rb', line 70

def members
  members = member_ids.map do |member_id|
    Member.find(member_id)
  end
  MultiAssociation.new(self, members).proxy
end

#saveObject

Save a record.



43
44
45
46
47
48
49
50
# File 'lib/trello/checklist.rb', line 43

def save
  return update! if id

  Client.post("/checklists", {
    :name    => name,
    :idBoard => board_id
  }).json_into(self)
end

#update!Object



52
53
54
# File 'lib/trello/checklist.rb', line 52

def update!
  Client.put("/checklists/#{id}", { :name => name }).json_into(self)
end

#update_fields(fields) ⇒ Object

Update the fields of a checklist.

Supply a hash of string keyed data retrieved from the Trello API representing a checklist.



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/trello/checklist.rb', line 25

def update_fields(fields)
  attributes[:id]          = fields['id']
  attributes[:name]        = fields['name']
  attributes[:description] = fields['desc']
  attributes[:closed]      = fields['closed']
  attributes[:url]         = fields['url']
  attributes[:check_items] = fields['checkItems']
  attributes[:board_id]    = fields['idBoard']
  attributes[:member_ids]  = fields['idMembers']
  self
end