Class: APDM::AdTech

Inherits:
Object
  • Object
show all
Defined in:
lib/apdm/ad_tech.rb,
lib/apdm/ad_tech/data.rb,
lib/apdm/ad_tech/ad_loader.rb

Defined Under Namespace

Classes: AdLoader, Data

Constant Summary collapse

FORMATS =
[:toppbanner, :bunnbanner, :skyskraper_1, :artikkelboard]

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(channel, options = {}) ⇒ AdTech

Returns a new instance of AdTech.



27
28
29
30
31
32
33
# File 'lib/apdm/ad_tech.rb', line 27

def initialize(channel, options = {})
  @channel = channel
  @context_key = options[:context_key]
  @loaders = []
  @data = options[:data] || AdTech.data.for(channel)
  @group_id = options[:group_id] || rand(10**10)
end

Class Attribute Details

.dataObject



21
22
23
# File 'lib/apdm/ad_tech.rb', line 21

def data
  @data ||= Data.new(path_to_csv_file)
end

.path_to_csv_fileObject



13
14
15
# File 'lib/apdm/ad_tech.rb', line 13

def path_to_csv_file
  @path_to_csv_file ||= File.dirname(__FILE__) + '/ad_tech/ads.csv'
end

Instance Attribute Details

#channelObject (readonly)

Returns the value of attribute channel.



26
27
28
# File 'lib/apdm/ad_tech.rb', line 26

def channel
  @channel
end

#dataObject (readonly)

Returns the value of attribute data.



26
27
28
# File 'lib/apdm/ad_tech.rb', line 26

def data
  @data
end

#group_idObject (readonly)

Returns the value of attribute group_id.



26
27
28
# File 'lib/apdm/ad_tech.rb', line 26

def group_id
  @group_id
end

#loadersObject (readonly)

Returns the value of attribute loaders.



26
27
28
# File 'lib/apdm/ad_tech.rb', line 26

def loaders
  @loaders
end

Class Method Details

.loadObject



17
18
19
# File 'lib/apdm/ad_tech.rb', line 17

def load
  @data = Data.new(path_to_csv_file)
end

Instance Method Details

#ad_loader(key, options = {}) ⇒ Object



45
46
47
# File 'lib/apdm/ad_tech.rb', line 45

def ad_loader(key, options = {})
  AdLoader.new data_for(key, options)
end

#context_key(refinement = nil) ⇒ Object



35
36
37
# File 'lib/apdm/ad_tech.rb', line 35

def context_key(refinement = nil)
  "#{@context_key}+#{refinement}".chomp('+')
end

#data_for(key, options = {}) ⇒ Object



78
79
80
# File 'lib/apdm/ad_tech.rb', line 78

def data_for(key, options = {})
  data[key].merge(:group_id => group_id, :context_key => context_key(options[:local_context]))
end

#loader_scriptsObject



58
59
60
61
62
63
64
65
66
# File 'lib/apdm/ad_tech.rb', line 58

def loader_scripts
  html = "<div id=\"adtech_loader_scripts\" style=\"display:none;\">\n"

  loaders.each do |loader|
    html << wrap(loader)
  end

  html << '</div>'
end

#placeholder_div(loader) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/apdm/ad_tech.rb', line 49

def placeholder_div(loader)
  s = <<-PLACEHOLDER.gsub(/^\s{8}/, '').chomp
    <div id="#{loader.dom_prefix}_placeholder" style="width: #{loader.width}px;">
      Annonse
    </div>

  PLACEHOLDER
end

#postloader(loader) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/apdm/ad_tech.rb', line 82

def postloader(loader)
  s = <<-SCRIPT
    <script>
      (function() {
        var loader = document.getElementById('#{loader.dom_prefix}_loader');
        var placeholder = document.getElementById('#{loader.dom_prefix}_placeholder');
        placeholder.innerHTML = loader.innerHTML;
        loader.innerHTML = '';
      }());
    </script>
  SCRIPT
end

#slot(key, options = {}) ⇒ Object



39
40
41
42
43
# File 'lib/apdm/ad_tech.rb', line 39

def slot(key, options = {})
  slotted = ad_loader(key, options)
  loaders << slotted
  placeholder_div slotted
end

#wrap(loader) ⇒ Object



68
69
70
71
72
73
74
75
76
# File 'lib/apdm/ad_tech.rb', line 68

def wrap(loader)
  s = <<-HTML.gsub(/^\s{8}/, '')
      <div id="#{loader.dom_prefix}_loader">
        #{loader}
     </div>
     #{postloader(loader)}
    HTML
  s
end