Class: AdZone
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- AdZone
- Defined in:
- app/models/ad_zone.rb
Overview
TODO: DB
Class Method Summary collapse
Instance Method Summary collapse
- #active_ads(options = {}) ⇒ Object
- #available? ⇒ Boolean
- #block_name ⇒ Object
- #display_name ⇒ Object
- #display_name_with_price ⇒ Object
- #height ⇒ Object
- #impression ⇒ Object
- #width ⇒ Object
Class Method Details
.load_ads(sid, ids, options = {}) ⇒ Object
53 54 55 56 57 58 59 |
# File 'app/models/ad_zone.rb', line 53 def AdZone.load_ads(sid, ids, = {}) ids = [ids] unless ids.instance_of?(Array) matching_ads = Ad.joins(:ad_zones).sys(sid).where("ad_zones.id in (#{ids.join(",")})").where(["? between ads.start_date and ads.end_date", Time.now]) matching_ads = matching_ads.where("ads.activated is not null") unless [:include_inactive] matching_ads = matching_ads.where("ads.approved_by_id is not null") unless [:include_unaproved] return matching_ads end |
Instance Method Details
#active_ads(options = {}) ⇒ Object
40 41 42 43 44 45 46 |
# File 'app/models/ad_zone.rb', line 40 def active_ads( = {}) [:date] ||= Time.now a = self.ads.where(["? between ads.start_date and ads.end_date", [:date]]) a = a.where("ads.activated is not null") unless [:include_inactive] a = a.where("ads.approved_by_id is not null") unless [:include_unapproved] end |
#available? ⇒ Boolean
48 49 50 51 |
# File 'app/models/ad_zone.rb', line 48 def available? return true if self.concurrency == 0 return active_ads.count < self.concurrency end |
#block_name ⇒ Object
10 11 12 |
# File 'app/models/ad_zone.rb', line 10 def block_name "Ad from zone '#{self.name}'" end |
#display_name ⇒ Object
18 19 20 |
# File 'app/models/ad_zone.rb', line 18 def display_name "#{self.name} (#{self.width}x#{self.height})" end |
#display_name_with_price ⇒ Object
14 15 16 |
# File 'app/models/ad_zone.rb', line 14 def display_name_with_price "#{self.name} (#{self.width}x#{self.height}) @ £#{('%.2f' % self.price_per_period)}/#{self.period.singularize}".html_safe end |
#height ⇒ Object
22 23 24 |
# File 'app/models/ad_zone.rb', line 22 def height self.ad_unit.height end |
#impression ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'app/models/ad_zone.rb', line 30 def impression if self.impressions_from == nil || self.impressions_from < Time.now - 1.day self.impression_count = 1 self.impressions_from = Time.now else self.impression_count += 1 end self.save end |
#width ⇒ Object
26 27 28 |
# File 'app/models/ad_zone.rb', line 26 def width self.ad_unit.width end |