Class: Collavre::Plan
- Inherits:
-
Label
- Object
- Label
- Collavre::Plan
- Defined in:
- app/models/collavre/plan.rb
Instance Method Summary collapse
- #progress(_user = nil) ⇒ Object
-
#start_date ⇒ Object
Delegate start_date to the associated creative’s created_at.
- #start_date=(value) ⇒ Object
Instance Method Details
#progress(_user = nil) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/models/collavre/plan.rb', line 8 def progress(_user = nil) tagged_ids = Tag.where(label_id: id).pluck(:creative_id) return 0 if tagged_ids.empty? root_ids = Creative.where(id: tagged_ids).map { |c| c.root.id }.uniq roots = Creative.where(id: root_ids) tagged_set = tagged_ids.to_set values = roots.map { |c| c.progress_for_plan(tagged_set) }.compact return 0 if values.empty? values.sum.to_f / values.size end |
#start_date ⇒ Object
Delegate start_date to the associated creative’s created_at
22 23 24 |
# File 'app/models/collavre/plan.rb', line 22 def start_date creative&.created_at&.to_date end |
#start_date=(value) ⇒ Object
26 27 28 29 30 31 |
# File 'app/models/collavre/plan.rb', line 26 def start_date=(value) return unless creative date = value.is_a?(Date) ? value : Date.parse(value.to_s) creative.update_column(:created_at, date.to_datetime) end |