Class: CampaignActivity

Inherits:
Object
  • Object
show all
Defined in:
app/models/campaign_activity.rb

Overview

A CampaignActivity design mainly a couple Campaign-Activity so it's not really an Activity. This model permits to manipulate the couple and compute results at its level

Instance Method Summary collapse

Constructor Details

#initialize(campaign, activity) ⇒ CampaignActivity

Returns a new instance of CampaignActivity.


5
6
7
8
# File 'app/models/campaign_activity.rb', line 5

def initialize(campaign, activity)
  @campaign = campaign
  @activity = activity
end

Instance Method Details

#cost_amountObject

Compute cost amount


17
18
19
# File 'app/models/campaign_activity.rb', line 17

def cost_amount
  productions.map(&:cost_amount).sum
end

#productionsObject

Returns list of CampaignProduction of current CampaignActivity


11
12
13
14
# File 'app/models/campaign_activity.rb', line 11

def productions
  @productions ||= @campaign.activity_productions.where(activity: @activity)
                            .map { |p| CampaignProduction.new(@campaign, p) }
end