Class: AdZone

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/ad_zone.rb

Overview

TODO: DB

Class Method Summary collapse

Instance Method Summary collapse

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, options = {})
  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 options[:include_inactive]
  matching_ads = matching_ads.where("ads.approved_by_id is not null") unless options[: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(options = {})
  options[:date] ||= Time.now

  a = self.ads.where(["? between ads.start_date and ads.end_date", options[:date]])
  a = a.where("ads.activated is not null") unless options[:include_inactive]
  a = a.where("ads.approved_by_id is not null") unless options[:include_unapproved]
end

#available?Boolean

Returns:

  • (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_nameObject



10
11
12
# File 'app/models/ad_zone.rb', line 10

def block_name
  "Ad from zone '#{self.name}'"
end

#display_nameObject



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_priceObject



14
15
16
# File 'app/models/ad_zone.rb', line 14

def display_name_with_price
  "#{self.name} (#{self.width}x#{self.height}) @ &pound;#{('%.2f' % self.price_per_period)}/#{self.period.singularize}".html_safe
end

#heightObject



22
23
24
# File 'app/models/ad_zone.rb', line 22

def height
  self.ad_unit.height
end

#impressionObject



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

#widthObject



26
27
28
# File 'app/models/ad_zone.rb', line 26

def width
  self.ad_unit.width
end