Class: Wiki2Go::GreyList

Inherits:
Object
  • Object
show all
Defined in:
lib/Wiki2Go/GreyList.rb

Defined Under Namespace

Classes: Suspect

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, items) ⇒ GreyList

Returns a new instance of GreyList.



39
40
41
42
43
44
45
46
# File 'lib/Wiki2Go/GreyList.rb', line 39

def initialize(name,items)
  @name   = name
  items = items.collect {|line| 
    user, url = line.strip.split
    (user.nil? || url.nil? ? nil : Suspect.new(user,url))
  }
  @banned = items.compact
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



37
38
39
# File 'lib/Wiki2Go/GreyList.rb', line 37

def name
  @name
end

Instance Method Details

#add(user, url) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/Wiki2Go/GreyList.rb', line 56

def add(user,url)
  if url =~ /(:\/\/[^\/:]+)/ then
    url = $1
  end

  url = escape_regex(url)
  @banned << Suspect.new(user,url)
  @banned = @banned.sort.uniq
end

#allObject



52
53
54
# File 'lib/Wiki2Go/GreyList.rb', line 52

def all
  return @banned.collect { |suspect| suspect.to_s }
end

#contains_url?(url) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
78
# File 'lib/Wiki2Go/GreyList.rb', line 75

def contains_url?(url)
  match = @banned.find { |ban| url =~ Regexp.new(ban.url,Regexp::IGNORECASE) }
  ! match.nil?
end

#contains_user?(user) ⇒ Boolean

Returns:

  • (Boolean)


70
71
72
73
# File 'lib/Wiki2Go/GreyList.rb', line 70

def contains_user?(user)
  match = @banned.find { |ban| user =~ Regexp.new(ban.user,Regexp::IGNORECASE) }
  ! match.nil?
end

#lengthObject



66
67
68
# File 'lib/Wiki2Go/GreyList.rb', line 66

def length
  return @banned.length
end

#remove(author, url) ⇒ Object



89
90
91
92
93
94
95
# File 'lib/Wiki2Go/GreyList.rb', line 89

def remove(author,url)
  if url =~ /(:\/\/[^\/:]+)/ then
    url = $1
  end
  url = escape_regex(url)
  @banned = @banned.reject { |suspect| suspect.user == author && suspect.url == url }
end

#suspectsObject



48
49
50
# File 'lib/Wiki2Go/GreyList.rb', line 48

def suspects
  return @banned
end

#url_found_in(lines) ⇒ Object



80
81
82
83
84
85
86
87
# File 'lib/Wiki2Go/GreyList.rb', line 80

def url_found_in(lines)
  lines = lines.join(' ') if lines.kind_of? Array
  @banned.each do | pattern |
    match  = Regexp.new(pattern.url,Regexp::IGNORECASE)
    return true if lines =~ match
  end
  return false
end