Class: Wiki2Go::BlackList
- Inherits:
-
Object
- Object
- Wiki2Go::BlackList
- Defined in:
- lib/Wiki2Go/BlackList.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #add(item) ⇒ Object
- #all ⇒ Object
- #contains(user) ⇒ Object
- #each(&block) ⇒ Object
- #found_in(lines) ⇒ Object
-
#initialize(name, items, normalize_urls = false) ⇒ BlackList
constructor
A new instance of BlackList.
- #length ⇒ Object
Constructor Details
#initialize(name, items, normalize_urls = false) ⇒ BlackList
Returns a new instance of BlackList.
8 9 10 11 12 13 14 15 16 |
# File 'lib/Wiki2Go/BlackList.rb', line 8 def initialize(name,items,normalize_urls=false) @name = name @banned = [] items = items.collect {|line| line.strip! (line.empty? || line[0] == '#'[0] ? nil : (normalize_urls ? normalize(line) : line )) } @banned = items.compact.sort.uniq end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/Wiki2Go/BlackList.rb', line 6 def name @name end |
Instance Method Details
#add(item) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/Wiki2Go/BlackList.rb', line 26 def add(item) if item =~ /(:\/\/([^\/:]+))/ then item = extract_domain($2) else item = escape_regex(item) end if !item.nil? then @banned << item @banned = @banned.sort.uniq end end |
#all ⇒ Object
18 19 20 |
# File 'lib/Wiki2Go/BlackList.rb', line 18 def all return @banned end |
#contains(user) ⇒ Object
42 43 44 45 |
# File 'lib/Wiki2Go/BlackList.rb', line 42 def contains(user) match = @banned.find { |ban| user =~ Regexp.new(ban,Regexp::IGNORECASE) } ! match.nil? end |
#each(&block) ⇒ Object
22 23 24 |
# File 'lib/Wiki2Go/BlackList.rb', line 22 def each(&block) @banned.each(&block) end |
#found_in(lines) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/Wiki2Go/BlackList.rb', line 47 def found_in(lines) lines = lines.join(' ') if lines.kind_of? Array @banned.each do | pattern | match = Regexp.new(pattern,Regexp::IGNORECASE) return true if lines =~ match end return false end |
#length ⇒ Object
38 39 40 |
# File 'lib/Wiki2Go/BlackList.rb', line 38 def length return @banned.length end |