Class: RecurrentDiscount
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- RecurrentDiscount
- Defined in:
- app/models/recurrent_discount.rb
Overview
Schema Information
Table name: recurrent_discounts
id :integer not null, primary key
title :text
description :text
url :string(255)
interval :integer
is_visible :boolean
created_at :datetime
updated_at :datetime
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.random_item(cookies = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'app/models/recurrent_discount.rb', line 39 def self.random_item( = {}) rand = visible.select { |i| [i.key].blank? }.sample if rand.present? [rand.key] = { value: true, expires: rand.expires } end rand end |
Instance Method Details
#expires ⇒ Object
35 36 37 |
# File 'app/models/recurrent_discount.rb', line 35 def expires Time.zone.now + interval.hours end |
#key ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'app/models/recurrent_discount.rb', line 26 def key @key ||= [ Settings.satellite_name.gsub(/[^a-z0-9]/i, '_').downcase, 'banner', id, updated_at.to_i.to_s(16) ].join('_') end |