Class: APDM::AdTech
- Inherits:
-
Object
- Object
- APDM::AdTech
- Defined in:
- lib/apdm/ad_tech.rb,
lib/apdm/ad_tech/data.rb,
lib/apdm/ad_tech/ad_loader.rb
Defined Under Namespace
Constant Summary collapse
- FORMATS =
[:toppbanner, :bunnbanner, :skyskraper_1, :artikkelboard]
Class Attribute Summary collapse
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#group_id ⇒ Object
readonly
Returns the value of attribute group_id.
-
#loaders ⇒ Object
readonly
Returns the value of attribute loaders.
Class Method Summary collapse
Instance Method Summary collapse
- #ad_loader(key, options = {}) ⇒ Object
- #context_key(refinement = nil) ⇒ Object
- #data_for(key, options = {}) ⇒ Object
-
#initialize(channel, options = {}) ⇒ AdTech
constructor
A new instance of AdTech.
- #loader_scripts ⇒ Object
- #placeholder_div(loader) ⇒ Object
- #postloader(loader) ⇒ Object
- #slot(key, options = {}) ⇒ Object
- #wrap(loader) ⇒ Object
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, = {}) @channel = channel @context_key = [:context_key] @loaders = [] @data = [:data] || AdTech.data.for(channel) @group_id = [:group_id] || rand(10**10) end |
Class Attribute Details
.data ⇒ Object
21 22 23 |
# File 'lib/apdm/ad_tech.rb', line 21 def data @data ||= Data.new(path_to_csv_file) end |
.path_to_csv_file ⇒ Object
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
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
26 27 28 |
# File 'lib/apdm/ad_tech.rb', line 26 def channel @channel end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
26 27 28 |
# File 'lib/apdm/ad_tech.rb', line 26 def data @data end |
#group_id ⇒ Object (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 |
#loaders ⇒ Object (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
Instance Method Details
#ad_loader(key, options = {}) ⇒ Object
45 46 47 |
# File 'lib/apdm/ad_tech.rb', line 45 def ad_loader(key, = {}) AdLoader.new data_for(key, ) 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, = {}) data[key].merge(:group_id => group_id, :context_key => context_key([:local_context])) end |
#loader_scripts ⇒ Object
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, = {}) slotted = ad_loader(key, ) 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 |