2018-07-25 09:30:33 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-11-13 18:20:48 +00:00
|
|
|
class GlobalLabel
|
2019-04-23 19:58:20 +00:00
|
|
|
include Presentable
|
|
|
|
|
2015-11-13 18:20:48 +00:00
|
|
|
attr_accessor :title, :labels
|
|
|
|
alias_attribute :name, :title
|
|
|
|
|
2019-04-02 10:48:20 +00:00
|
|
|
delegate :color, :text_color, :description, :scoped_label?, to: :@first_label
|
2016-03-07 04:07:19 +00:00
|
|
|
|
2016-10-06 21:17:11 +00:00
|
|
|
def for_display
|
|
|
|
@first_label
|
|
|
|
end
|
|
|
|
|
2015-11-13 18:20:48 +00:00
|
|
|
def self.build_collection(labels)
|
|
|
|
labels = labels.group_by(&:title)
|
|
|
|
|
2016-03-07 04:07:19 +00:00
|
|
|
labels.map do |title, labels|
|
|
|
|
new(title, labels)
|
2015-11-13 18:20:48 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(title, labels)
|
|
|
|
@title = title
|
|
|
|
@labels = labels
|
2016-03-07 04:07:19 +00:00
|
|
|
@first_label = labels.find { |lbl| lbl.description.present? } || labels.first
|
2015-11-13 18:20:48 +00:00
|
|
|
end
|
2019-04-23 19:58:20 +00:00
|
|
|
|
|
|
|
def present(attributes)
|
|
|
|
super(attributes.merge(presenter_class: ::LabelPresenter))
|
|
|
|
end
|
2015-11-13 18:20:48 +00:00
|
|
|
end
|