Class: APDM::Network

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/apdm/network.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNetwork

Returns a new instance of Network.



9
10
11
# File 'lib/apdm/network.rb', line 9

def initialize
  @channels = []
end

Instance Attribute Details

#channelsObject (readonly)

Returns the value of attribute channels.



8
9
10
# File 'lib/apdm/network.rb', line 8

def channels
  @channels
end

Instance Method Details

#<<(channel) ⇒ Object



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

def <<(channel)
  @channels << channel
end

#eachObject



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

def each
  @channels.each {|c| yield c}
end

#find_by_ad_tech_id(id) ⇒ Object



27
28
29
30
31
# File 'lib/apdm/network.rb', line 27

def find_by_ad_tech_id(id)
  find do |channel|
    channel.ad_tech_id == id.to_i
  end
end

#find_by_domain(url) ⇒ Object

DEPRECATED



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

def find_by_domain(url)
  find_by_url(url)
end

#find_by_label(label) ⇒ Object



21
22
23
24
25
# File 'lib/apdm/network.rb', line 21

def find_by_label(label)
  find do |channel|
    channel.label == label
  end
end

#find_by_url(url) ⇒ Object



33
34
35
36
37
# File 'lib/apdm/network.rb', line 33

def find_by_url(url)
  return nil unless (url && url[/\./])
  label = url.gsub(/https?:\/\//, '')[/([^\.]+\.[^\.]+)$/, 1].gsub(/\.\w+$/, '')
  find_by_label(label)
end

#random_production_channelObject



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

def random_production_channel
  # used to display ads from a random channel
  @channels.reject{|c| c.ad_tech_id.nil? || c.label == 'avisnavn' || c.label == 'moss-dagblad' }.sample
end