global_label.rb 534 Bytes
Newer Older
1 2
# frozen_string_literal: true

3 4 5 6
class GlobalLabel
  attr_accessor :title, :labels
  alias_attribute :name, :title

7
  delegate :color, :text_color, :description, to: :@first_label
8

9 10 11 12
  def for_display
    @first_label
  end

13 14 15
  def self.build_collection(labels)
    labels = labels.group_by(&:title)

16 17
    labels.map do |title, labels|
      new(title, labels)
18 19 20 21 22 23
    end
  end

  def initialize(title, labels)
    @title = title
    @labels = labels
24
    @first_label = labels.find { |lbl| lbl.description.present? } || labels.first
25 26
  end
end