문제

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