2015-11-13 13:20:48 -05:00
|
|
|
class GlobalLabel
|
|
|
|
attr_accessor :title, :labels
|
|
|
|
alias_attribute :name, :title
|
|
|
|
|
2016-03-06 23:07:19 -05:00
|
|
|
delegate :color, :description, to: :@first_label
|
|
|
|
|
2016-10-06 17:17:11 -04:00
|
|
|
def for_display
|
|
|
|
@first_label
|
|
|
|
end
|
|
|
|
|
2015-11-13 13:20:48 -05:00
|
|
|
def self.build_collection(labels)
|
|
|
|
labels = labels.group_by(&:title)
|
|
|
|
|
2016-03-06 23:07:19 -05:00
|
|
|
labels.map do |title, labels|
|
|
|
|
new(title, labels)
|
2015-11-13 13:20:48 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(title, labels)
|
|
|
|
@title = title
|
|
|
|
@labels = labels
|
2016-03-06 23:07:19 -05:00
|
|
|
@first_label = labels.find { |lbl| lbl.description.present? } || labels.first
|
2015-11-13 13:20:48 -05:00
|
|
|
end
|
|
|
|
end
|