I'm working on modifying Brett Weaver's Trello CLI ruby-based utility to include information from a Trello card object, namely the label colors associated with that card. Right now, I can do something like the following to iterate through the labels on each card:

list_cards.each_with_index do |card, i|

  puts "#{i+1} #{card.name}"

    card.labels.each do |label|
      puts "(#{label.name})"
    end
end

Rather than printing the label.name attribute, I would prefer to print a solid colored square that corresponds to the label.color attribute. An example of this can be seen in another library seen here. I've read about using the colorize library to get the color, but first I can't figure out how to get it to print a color dynamically rather than explicitly and second, I can't figure out how I would print a square. Additionally, the colorize gem doesn't have the range of colors that are needed from Trello (like orange or purple).

有帮助吗?

解决方案

With the colorize gem, all you need to do is print two spaces on a background color, like:

puts "  ".colorize(background: :blue)

to display a blue square.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top