Class: Wiki2Go::GreyList
- Inherits:
-
Object
- Object
- Wiki2Go::GreyList
- Defined in:
- lib/Wiki2Go/GreyList.rb
Defined Under Namespace
Classes: Suspect
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #add(user, url) ⇒ Object
- #all ⇒ Object
- #contains_url?(url) ⇒ Boolean
- #contains_user?(user) ⇒ Boolean
-
#initialize(name, items) ⇒ GreyList
constructor
A new instance of GreyList.
- #length ⇒ Object
- #remove(author, url) ⇒ Object
- #suspects ⇒ Object
- #url_found_in(lines) ⇒ Object
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
#name ⇒ Object (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 |
#all ⇒ Object
52 53 54 |
# File 'lib/Wiki2Go/GreyList.rb', line 52 def all return @banned.collect { |suspect| suspect.to_s } end |
#contains_url?(url) ⇒ 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
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 |
#length ⇒ Object
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(,url) if url =~ /(:\/\/[^\/:]+)/ then url = $1 end url = escape_regex(url) @banned = @banned.reject { |suspect| suspect.user == && suspect.url == url } end |
#suspects ⇒ Object
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 |