Class: ChannelGrouping::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/channel_grouping/source.rb

Constant Summary collapse

CONFIG_FILENAME =
'sources.yml'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Source

Returns a new instance of Source.



12
13
14
# File 'lib/channel_grouping/source.rb', line 12

def initialize(url)
  @url = url
end

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



10
11
12
# File 'lib/channel_grouping/source.rb', line 10

def url
  @url
end

Class Method Details

.configObject



44
45
46
47
# File 'lib/channel_grouping/source.rb', line 44

def self.config
  root = Pathname.new(File.expand_path("../../..", __FILE__))
  YAML.load_file(root.join(CONFIG_FILENAME))
end

.search_enginesObject



40
41
42
# File 'lib/channel_grouping/source.rb', line 40

def self.search_engines
  @search_engines ||= config['search_engines']
end

.social_networksObject



36
37
38
# File 'lib/channel_grouping/source.rb', line 36

def self.social_networks
  @social_networks ||= config['social_networks']
end

Instance Method Details

#direct?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/channel_grouping/source.rb', line 28

def direct?
  uri.host.nil?
end

#hostObject



32
33
34
# File 'lib/channel_grouping/source.rb', line 32

def host
  uri.host
end

#search_engine?Boolean

Returns:

  • (Boolean)


16
17
18
19
20
# File 'lib/channel_grouping/source.rb', line 16

def search_engine?
  self.class.search_engines.any? do |search_engine_host|
    host_matches?(search_engine_host)
  end
end

#social_network?Boolean

Returns:

  • (Boolean)


22
23
24
25
26
# File 'lib/channel_grouping/source.rb', line 22

def social_network?
  self.class.social_networks.any? do |social_network_host|
    host_matches?(social_network_host)
  end
end