Skip to content

Instantly share code, notes, and snippets.

@MikeSilvis
Created October 15, 2012 18:36
Show Gist options
  • Save MikeSilvis/3894236 to your computer and use it in GitHub Desktop.
Save MikeSilvis/3894236 to your computer and use it in GitHub Desktop.
hot or not
def class_for_cities_deal(deal, opts = {})
@deal_classes ||= {}
@hot_count ||= 0
@shared_count ||= 0
collection_size = opts.fetch(:collection_size){ 10 }
return @deal_classes[deal.id] if @deal_classes.keys.include?(deal.id)
deal_class = case
# when deal_in_campaign_and_banner_title?(deal) then "deal_campaign"
# when deal.sold_out? then 'sold_out'
# when deal.id==top_deal.try(:id) then 'featured_deal'
# when deal.display_remaining_on_list? then 'reveal_orders_remaining'
when ((@hot_count < (collection_size*0.15).ceil) && deal.currently_hot?) then 'hot_deal'
when ((@shared_count < (collection_size*0.05).ceil) && deal.most_shared?) then 'most_shared'
# when deal.ends_soon? then 'ends_soon'
# when deal.started_today? then 'started_today'
# else
# ''
end
@hot_count +=1 if deal_class=='hot_deal'
@shared_count +=1 if deal_class=='most_shared'
@deal_classes[deal.id] = deal_class
deal_class
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment