2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-11-26 14:37:03 +05:30
|
|
|
class GlobalLabel
|
|
|
|
attr_accessor :title, :labels
|
|
|
|
alias_attribute :name, :title
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
delegate :color, :text_color, :description, to: :@first_label
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
def for_display
|
|
|
|
@first_label
|
|
|
|
end
|
|
|
|
|
2015-11-26 14:37:03 +05:30
|
|
|
def self.build_collection(labels)
|
|
|
|
labels = labels.group_by(&:title)
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
labels.map do |title, labels|
|
|
|
|
new(title, labels)
|
2015-11-26 14:37:03 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(title, labels)
|
|
|
|
@title = title
|
|
|
|
@labels = labels
|
2016-06-02 11:05:42 +05:30
|
|
|
@first_label = labels.find { |lbl| lbl.description.present? } || labels.first
|
2015-11-26 14:37:03 +05:30
|
|
|
end
|
|
|
|
end
|