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.
- #check_items ⇒ Object readonly
- #closed ⇒ Boolean readonly
- #description ⇒ String readonly
- #id ⇒ String readonly
-
#list_id ⇒ String
readonly
A 24-character hex string.
-
#member_ids ⇒ Array<String>
readonly
An array of 24-character hex strings.
- #name ⇒ String
- #position ⇒ Object
- #url ⇒ String readonly
Attributes inherited from BasicData
Class Method Summary collapse
- .create(options) ⇒ Object
-
.find(id, params = {}) ⇒ Object
Locate a specific checklist by its id.
Instance Method Summary collapse
-
#add_item(name, checked = false, position = 'bottom') ⇒ Object
Add an item to the checklist.
-
#closed? ⇒ Boolean
Check if the checklist is currently active.
-
#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.
-
#members ⇒ Object
Return a list of members active in this checklist.
-
#save ⇒ Object
Save a record.
- #update! ⇒ Object
-
#update_fields(fields) ⇒ Object
Update the fields of a checklist.
Methods inherited from BasicData
#==, client, #initialize, many, one, parse, parse_many, path_name, #refresh!, register_attributes, save
Constructor Details
This class inherits a constructor from Trello::BasicData
Instance Attribute Details
#board_id ⇒ String (readonly)
Returns A 24-character hex string.
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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/trello/checklist.rb', line 24 class Checklist < BasicData register_attributes :id, :name, :description, :closed, :position, :url, :check_items, :board_id, :list_id, :member_ids, readonly: [:id, :description, :closed, :url, :check_items, :board_id, :list_id, :member_ids] validates_presence_of :id, :board_id, :list_id validates_length_of :name, in: 1..16384 class << self # Locate a specific checklist by its id. def find(id, params = {}) client.find(:checklist, id, params) end def create() client.create(:checklist, 'name' => [:name], 'idBoard' => [:board_id]) end end # Update the fields of a checklist. # # Supply a hash of string keyed data retrieved from the Trello API representing # a checklist. 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[:position] = fields['pos'] attributes[:board_id] = fields['idBoard'] attributes[:list_id] = fields['idList'] attributes[:member_ids] = fields['idMembers'] self end # Check if the checklist is currently active. def closed? closed end # Save a record. def save return update! if id client.post("/checklists", { name: name, idBoard: board_id }).json_into(self) end def update! client.put("/checklists/#{id}", {name: name, pos: position}).json_into(self) end # 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 list the checklist is on. one :list, path: :lists, using: :list_id # Return a list of members active in this checklist. def members members = member_ids.map do |member_id| Member.find(member_id) end MultiAssociation.new(self, members).proxy end # 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 # 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) 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)
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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/trello/checklist.rb', line 24 class Checklist < BasicData register_attributes :id, :name, :description, :closed, :position, :url, :check_items, :board_id, :list_id, :member_ids, readonly: [:id, :description, :closed, :url, :check_items, :board_id, :list_id, :member_ids] validates_presence_of :id, :board_id, :list_id validates_length_of :name, in: 1..16384 class << self # Locate a specific checklist by its id. def find(id, params = {}) client.find(:checklist, id, params) end def create() client.create(:checklist, 'name' => [:name], 'idBoard' => [:board_id]) end end # Update the fields of a checklist. # # Supply a hash of string keyed data retrieved from the Trello API representing # a checklist. 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[:position] = fields['pos'] attributes[:board_id] = fields['idBoard'] attributes[:list_id] = fields['idList'] attributes[:member_ids] = fields['idMembers'] self end # Check if the checklist is currently active. def closed? closed end # Save a record. def save return update! if id client.post("/checklists", { name: name, idBoard: board_id }).json_into(self) end def update! client.put("/checklists/#{id}", {name: name, pos: position}).json_into(self) end # 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 list the checklist is on. one :list, path: :lists, using: :list_id # Return a list of members active in this checklist. def members members = member_ids.map do |member_id| Member.find(member_id) end MultiAssociation.new(self, members).proxy end # 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 # 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) 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 |
#closed ⇒ Boolean (readonly)
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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/trello/checklist.rb', line 24 class Checklist < BasicData register_attributes :id, :name, :description, :closed, :position, :url, :check_items, :board_id, :list_id, :member_ids, readonly: [:id, :description, :closed, :url, :check_items, :board_id, :list_id, :member_ids] validates_presence_of :id, :board_id, :list_id validates_length_of :name, in: 1..16384 class << self # Locate a specific checklist by its id. def find(id, params = {}) client.find(:checklist, id, params) end def create() client.create(:checklist, 'name' => [:name], 'idBoard' => [:board_id]) end end # Update the fields of a checklist. # # Supply a hash of string keyed data retrieved from the Trello API representing # a checklist. 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[:position] = fields['pos'] attributes[:board_id] = fields['idBoard'] attributes[:list_id] = fields['idList'] attributes[:member_ids] = fields['idMembers'] self end # Check if the checklist is currently active. def closed? closed end # Save a record. def save return update! if id client.post("/checklists", { name: name, idBoard: board_id }).json_into(self) end def update! client.put("/checklists/#{id}", {name: name, pos: position}).json_into(self) end # 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 list the checklist is on. one :list, path: :lists, using: :list_id # Return a list of members active in this checklist. def members members = member_ids.map do |member_id| Member.find(member_id) end MultiAssociation.new(self, members).proxy end # 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 # 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) 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 |
#description ⇒ String (readonly)
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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/trello/checklist.rb', line 24 class Checklist < BasicData register_attributes :id, :name, :description, :closed, :position, :url, :check_items, :board_id, :list_id, :member_ids, readonly: [:id, :description, :closed, :url, :check_items, :board_id, :list_id, :member_ids] validates_presence_of :id, :board_id, :list_id validates_length_of :name, in: 1..16384 class << self # Locate a specific checklist by its id. def find(id, params = {}) client.find(:checklist, id, params) end def create() client.create(:checklist, 'name' => [:name], 'idBoard' => [:board_id]) end end # Update the fields of a checklist. # # Supply a hash of string keyed data retrieved from the Trello API representing # a checklist. 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[:position] = fields['pos'] attributes[:board_id] = fields['idBoard'] attributes[:list_id] = fields['idList'] attributes[:member_ids] = fields['idMembers'] self end # Check if the checklist is currently active. def closed? closed end # Save a record. def save return update! if id client.post("/checklists", { name: name, idBoard: board_id }).json_into(self) end def update! client.put("/checklists/#{id}", {name: name, pos: position}).json_into(self) end # 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 list the checklist is on. one :list, path: :lists, using: :list_id # Return a list of members active in this checklist. def members members = member_ids.map do |member_id| Member.find(member_id) end MultiAssociation.new(self, members).proxy end # 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 # 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) 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)
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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/trello/checklist.rb', line 24 class Checklist < BasicData register_attributes :id, :name, :description, :closed, :position, :url, :check_items, :board_id, :list_id, :member_ids, readonly: [:id, :description, :closed, :url, :check_items, :board_id, :list_id, :member_ids] validates_presence_of :id, :board_id, :list_id validates_length_of :name, in: 1..16384 class << self # Locate a specific checklist by its id. def find(id, params = {}) client.find(:checklist, id, params) end def create() client.create(:checklist, 'name' => [:name], 'idBoard' => [:board_id]) end end # Update the fields of a checklist. # # Supply a hash of string keyed data retrieved from the Trello API representing # a checklist. 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[:position] = fields['pos'] attributes[:board_id] = fields['idBoard'] attributes[:list_id] = fields['idList'] attributes[:member_ids] = fields['idMembers'] self end # Check if the checklist is currently active. def closed? closed end # Save a record. def save return update! if id client.post("/checklists", { name: name, idBoard: board_id }).json_into(self) end def update! client.put("/checklists/#{id}", {name: name, pos: position}).json_into(self) end # 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 list the checklist is on. one :list, path: :lists, using: :list_id # Return a list of members active in this checklist. def members members = member_ids.map do |member_id| Member.find(member_id) end MultiAssociation.new(self, members).proxy end # 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 # 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) 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 |
#list_id ⇒ String (readonly)
Returns A 24-character hex string.
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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/trello/checklist.rb', line 24 class Checklist < BasicData register_attributes :id, :name, :description, :closed, :position, :url, :check_items, :board_id, :list_id, :member_ids, readonly: [:id, :description, :closed, :url, :check_items, :board_id, :list_id, :member_ids] validates_presence_of :id, :board_id, :list_id validates_length_of :name, in: 1..16384 class << self # Locate a specific checklist by its id. def find(id, params = {}) client.find(:checklist, id, params) end def create() client.create(:checklist, 'name' => [:name], 'idBoard' => [:board_id]) end end # Update the fields of a checklist. # # Supply a hash of string keyed data retrieved from the Trello API representing # a checklist. 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[:position] = fields['pos'] attributes[:board_id] = fields['idBoard'] attributes[:list_id] = fields['idList'] attributes[:member_ids] = fields['idMembers'] self end # Check if the checklist is currently active. def closed? closed end # Save a record. def save return update! if id client.post("/checklists", { name: name, idBoard: board_id }).json_into(self) end def update! client.put("/checklists/#{id}", {name: name, pos: position}).json_into(self) end # 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 list the checklist is on. one :list, path: :lists, using: :list_id # Return a list of members active in this checklist. def members members = member_ids.map do |member_id| Member.find(member_id) end MultiAssociation.new(self, members).proxy end # 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 # 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) 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 |
#member_ids ⇒ Array<String> (readonly)
Returns An array of 24-character hex strings.
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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/trello/checklist.rb', line 24 class Checklist < BasicData register_attributes :id, :name, :description, :closed, :position, :url, :check_items, :board_id, :list_id, :member_ids, readonly: [:id, :description, :closed, :url, :check_items, :board_id, :list_id, :member_ids] validates_presence_of :id, :board_id, :list_id validates_length_of :name, in: 1..16384 class << self # Locate a specific checklist by its id. def find(id, params = {}) client.find(:checklist, id, params) end def create() client.create(:checklist, 'name' => [:name], 'idBoard' => [:board_id]) end end # Update the fields of a checklist. # # Supply a hash of string keyed data retrieved from the Trello API representing # a checklist. 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[:position] = fields['pos'] attributes[:board_id] = fields['idBoard'] attributes[:list_id] = fields['idList'] attributes[:member_ids] = fields['idMembers'] self end # Check if the checklist is currently active. def closed? closed end # Save a record. def save return update! if id client.post("/checklists", { name: name, idBoard: board_id }).json_into(self) end def update! client.put("/checklists/#{id}", {name: name, pos: position}).json_into(self) end # 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 list the checklist is on. one :list, path: :lists, using: :list_id # Return a list of members active in this checklist. def members members = member_ids.map do |member_id| Member.find(member_id) end MultiAssociation.new(self, members).proxy end # 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 # 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) 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
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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/trello/checklist.rb', line 24 class Checklist < BasicData register_attributes :id, :name, :description, :closed, :position, :url, :check_items, :board_id, :list_id, :member_ids, readonly: [:id, :description, :closed, :url, :check_items, :board_id, :list_id, :member_ids] validates_presence_of :id, :board_id, :list_id validates_length_of :name, in: 1..16384 class << self # Locate a specific checklist by its id. def find(id, params = {}) client.find(:checklist, id, params) end def create() client.create(:checklist, 'name' => [:name], 'idBoard' => [:board_id]) end end # Update the fields of a checklist. # # Supply a hash of string keyed data retrieved from the Trello API representing # a checklist. 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[:position] = fields['pos'] attributes[:board_id] = fields['idBoard'] attributes[:list_id] = fields['idList'] attributes[:member_ids] = fields['idMembers'] self end # Check if the checklist is currently active. def closed? closed end # Save a record. def save return update! if id client.post("/checklists", { name: name, idBoard: board_id }).json_into(self) end def update! client.put("/checklists/#{id}", {name: name, pos: position}).json_into(self) end # 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 list the checklist is on. one :list, path: :lists, using: :list_id # Return a list of members active in this checklist. def members members = member_ids.map do |member_id| Member.find(member_id) end MultiAssociation.new(self, members).proxy end # 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 # 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) 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
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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/trello/checklist.rb', line 24 class Checklist < BasicData register_attributes :id, :name, :description, :closed, :position, :url, :check_items, :board_id, :list_id, :member_ids, readonly: [:id, :description, :closed, :url, :check_items, :board_id, :list_id, :member_ids] validates_presence_of :id, :board_id, :list_id validates_length_of :name, in: 1..16384 class << self # Locate a specific checklist by its id. def find(id, params = {}) client.find(:checklist, id, params) end def create() client.create(:checklist, 'name' => [:name], 'idBoard' => [:board_id]) end end # Update the fields of a checklist. # # Supply a hash of string keyed data retrieved from the Trello API representing # a checklist. 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[:position] = fields['pos'] attributes[:board_id] = fields['idBoard'] attributes[:list_id] = fields['idList'] attributes[:member_ids] = fields['idMembers'] self end # Check if the checklist is currently active. def closed? closed end # Save a record. def save return update! if id client.post("/checklists", { name: name, idBoard: board_id }).json_into(self) end def update! client.put("/checklists/#{id}", {name: name, pos: position}).json_into(self) end # 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 list the checklist is on. one :list, path: :lists, using: :list_id # Return a list of members active in this checklist. def members members = member_ids.map do |member_id| Member.find(member_id) end MultiAssociation.new(self, members).proxy end # 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 # 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) 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 |
#url ⇒ String (readonly)
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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/trello/checklist.rb', line 24 class Checklist < BasicData register_attributes :id, :name, :description, :closed, :position, :url, :check_items, :board_id, :list_id, :member_ids, readonly: [:id, :description, :closed, :url, :check_items, :board_id, :list_id, :member_ids] validates_presence_of :id, :board_id, :list_id validates_length_of :name, in: 1..16384 class << self # Locate a specific checklist by its id. def find(id, params = {}) client.find(:checklist, id, params) end def create() client.create(:checklist, 'name' => [:name], 'idBoard' => [:board_id]) end end # Update the fields of a checklist. # # Supply a hash of string keyed data retrieved from the Trello API representing # a checklist. 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[:position] = fields['pos'] attributes[:board_id] = fields['idBoard'] attributes[:list_id] = fields['idList'] attributes[:member_ids] = fields['idMembers'] self end # Check if the checklist is currently active. def closed? closed end # Save a record. def save return update! if id client.post("/checklists", { name: name, idBoard: board_id }).json_into(self) end def update! client.put("/checklists/#{id}", {name: name, pos: position}).json_into(self) end # 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 list the checklist is on. one :list, path: :lists, using: :list_id # Return a list of members active in this checklist. def members members = member_ids.map do |member_id| Member.find(member_id) end MultiAssociation.new(self, members).proxy end # 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 # 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) 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 |
Class Method Details
.create(options) ⇒ Object
36 37 38 39 40 |
# File 'lib/trello/checklist.rb', line 36 def create() client.create(:checklist, 'name' => [:name], 'idBoard' => [:board_id]) end |
.find(id, params = {}) ⇒ Object
Locate a specific checklist by its id.
32 33 34 |
# File 'lib/trello/checklist.rb', line 32 def find(id, params = {}) client.find(:checklist, id, params) end |
Instance Method Details
#add_item(name, checked = false, position = 'bottom') ⇒ Object
Add an item to the checklist
102 103 104 |
# File 'lib/trello/checklist.rb', line 102 def add_item(name, checked=false, position='bottom') client.post("/checklists/#{id}/checkItems", {name: name, checked: checked, pos: position}) end |
#closed? ⇒ Boolean
Check if the checklist is currently active.
62 63 64 |
# File 'lib/trello/checklist.rb', line 62 def closed? closed end |
#copy ⇒ Object
Copy a checklist (i.e., same attributes, items, etc.)
117 118 119 120 121 |
# File 'lib/trello/checklist.rb', line 117 def copy checklist_copy = self.class.create(name: self.name, board_id: self.board_id) copy_items_to(checklist_copy) return checklist_copy end |
#delete ⇒ Object
Delete a checklist
112 113 114 |
# File 'lib/trello/checklist.rb', line 112 def delete client.delete("/checklists/#{id}") end |
#delete_checklist_item(item_id) ⇒ Object
Delete a checklist item
107 108 109 |
# File 'lib/trello/checklist.rb', line 107 def delete_checklist_item(item_id) client.delete("/checklists/#{id}/checkItems/#{item_id}") end |
#items ⇒ Object
Return a list of items on the checklist.
81 82 83 84 85 |
# File 'lib/trello/checklist.rb', line 81 def items check_items.map do |item_fields| Item.new(item_fields) end end |
#members ⇒ Object
Return a list of members active in this checklist.
94 95 96 97 98 99 |
# File 'lib/trello/checklist.rb', line 94 def members members = member_ids.map do |member_id| Member.find(member_id) end MultiAssociation.new(self, members).proxy end |
#save ⇒ Object
Save a record.
67 68 69 70 71 72 73 74 |
# File 'lib/trello/checklist.rb', line 67 def save return update! if id client.post("/checklists", { name: name, idBoard: board_id }).json_into(self) end |
#update! ⇒ Object
76 77 78 |
# File 'lib/trello/checklist.rb', line 76 def update! client.put("/checklists/#{id}", {name: name, pos: position}).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.
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/trello/checklist.rb', line 47 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[:position] = fields['pos'] attributes[:board_id] = fields['idBoard'] attributes[:list_id] = fields['idList'] attributes[:member_ids] = fields['idMembers'] self end |