Class: FeedFilter::AdsFilters

Inherits:
Object
  • Object
show all
Includes:
LogUtils::Logging
Defined in:
lib/feedfilter/ads.rb

Instance Method Summary collapse

Constructor Details

#initializeAdsFilters

Returns a new instance of AdsFilters.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/feedfilter/ads.rb', line 11

def initialize
  @filters=[]

  names=[
    'feedburner',
    'feedflare'
  ]

  names.each do |name|
    logger.debug "  add ads filter #{name}"

    b = BlockReader.from_file( "#{FeedFilter.root}/config/#{name}.txt").read
    ## Note: replace newline and space in string for regex (w/o spaces)
    ## Note: add multiline option and ignore case
    regexp = Regexp.new( b[0].gsub( /[\n ]/, '' ), Regexp::MULTILINE|Regexp::IGNORECASE )
    @filters << [name, regexp]
  end
end

Instance Method Details

#filter(text) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/feedfilter/ads.rb', line 30

def filter( text )
  @filters.each do |f|
    name     = f[0]
    pattern  = f[1]
    
    text = text.gsub( pattern ) do |m|
      # Note: m - match is just a regular string
      ##  double check if it's true also if regex contains capture groups ???
      puts "strip #{name}:"
      pp m
      ''
    end
  end # each filter
  text
end