class Trello::Label

A colored Label attached to a card

@!attribute [rw] id

@return [String]

@!attribute [rw] color

@return [String]

Constants

SYMBOL_TO_STRING
VALID_LABEL_COLOURS

Public Class Methods

create(options) click to toggle source

Create a new label and save it on Trello.

# File lib/trello/label.rb, line 32
def create(options)
  client.create(:label,
    'name' => options[:name],
    'idBoard' => options[:board_id],
    'color'   => options[:color],
  )
end
find(id, params = {}) click to toggle source

Find a specific card by its id.

# File lib/trello/label.rb, line 27
def find(id, params = {})
  client.find(:label, id, params)
end
label_colours() click to toggle source

Label colours

# File lib/trello/label.rb, line 41
def label_colours
  VALID_LABEL_COLOURS
end

Public Instance Methods

color() click to toggle source
# File lib/trello/label.rb, line 48
def color
  @attributes[:color]
end
color=(colour) click to toggle source
# File lib/trello/label.rb, line 52
def color= colour
  unless Label.label_colours.include? colour
    errors.add(:label, "color '#{colour}' does not exist")
    return Trello.logger.warn "The label colour '#{colour}' does not exist."
  end

  self.send(:"color_will_change!") unless colour == @attributes[:color]
  @attributes[:color] = colour
end
delete() click to toggle source

Delete this label

# File lib/trello/label.rb, line 104
def delete
  client.delete("/labels/#{id}")
end
save() click to toggle source

Saves a record.

# File lib/trello/label.rb, line 79
def save
  # If we have an id, just update our fields.
  return update! if id

  from_response client.post("/labels", {
    name:   name,
    color:   color,
    idBoard: board_id,
  })
end
update!() click to toggle source

Update an existing record. Warning, this updates all fields using values already in memory. If an external resource has updated these fields, you should refresh! this object before making your changes, and before updating the record.

# File lib/trello/label.rb, line 94
def update!
  @previously_changed = changes
  # extract only new values to build payload
  payload = Hash[changes.map { |key, values| [SYMBOL_TO_STRING[key.to_sym].to_sym, values[1]] }]
  @changed_attributes.clear

  client.put("/labels/#{id}", payload)
end
update_fields(fields) click to toggle source

Update the fields of a label.

Supply a hash of stringkeyed data retrieved from the Trello API representing a label.

# File lib/trello/label.rb, line 66
def update_fields(fields)
  attributes[:id] = fields['id'] || attributes[:id]
  attributes[:name]  = fields['name'] || fields[:name] || attributes[:name]
  attributes[:color] = fields['color'] || fields[:color] || attributes[:color]
  attributes[:board_id] = fields['idBoard'] || fields[:board_id] || attributes[:board_id]
  attributes[:uses] = fields['uses'] if fields.has_key?('uses')
  self
end