Read about our upcoming Code of Conduct on this issue

global_label.rb 490 Bytes
Newer Older
1
2
3
4
class GlobalLabel
  attr_accessor :title, :labels
  alias_attribute :name, :title

5
6
  delegate :color, :description, to: :@first_label

7
8
9
10
  def for_display
    @first_label
  end

11
12
13
  def self.build_collection(labels)
    labels = labels.group_by(&:title)

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

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