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



49
50
51
52
53
54
55
# File 'app/models/ad_zone.rb', line 49

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



36
37
38
39
40
41
42
# File 'app/models/ad_zone.rb', line 36

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)


44
45
46
47
# File 'app/models/ad_zone.rb', line 44

def available?
  return true if self.concurrency == 0 
  return active_ads.count < self.concurrency
end

#display_nameObject



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

def display_name
  "#{self.name} (#{self.width}x#{self.height})"
end

#display_name_with_priceObject



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

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



18
19
20
# File 'app/models/ad_zone.rb', line 18

def height
  self.ad_unit.height
end

#impressionObject



26
27
28
29
30
31
32
33
34
# File 'app/models/ad_zone.rb', line 26

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



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

def width
  self.ad_unit.width
end