Skip to content

Instantly share code, notes, and snippets.

@rossmari
Last active April 20, 2016 08:50
Show Gist options
  • Save rossmari/a13805c84540fab106fc49e70570938c to your computer and use it in GitHub Desktop.
Save rossmari/a13805c84540fab106fc49e70570938c to your computer and use it in GitHub Desktop.
For wwwermishel. Example.
module CampaignsHelper
COLORS = [
{ percents: [-1], color: 'gray', message: 'no_capping'},
{ percents: 0..30, color: 'red', message: 'msg'},
{ percents: 30..70, color: 'yellow', message: 'msg'},
{ percents: 70..100, color: 'green', message: 'msg'}
]
def campaign_state(draft_campaign)
campaign = Campaign.find(draft_campaign.campaign_id)
data =
if campaign.has_freq_cap_ecpm_calculating
percent = campaign_capping_percent(campaign)
select_colors_data(percent)
else
select_colors_data(-1)
end
get_state_html(data[:color], data[:msg], data[:percent])
end
def get_state_html(color, msg, percent = nil)
haml_tag :span, class: "campaign_state #{color}", title: t("direct_offers.index.headers.states.#{msg}", percent: percent)
end
def select_colors_data(percents_value)
COLORS.detect{|data| data[:percents].to_a.include?(percents_value.to_i)}
end
def campaign_capping_percent(campaign)
if campaign.frequency_capping_value.to_i.zero?
0.0
else
campaign.frequency_capping_counter.to_i * 100 / campaign.frequency_capping_value.to_f
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment