Class: ContentCheckerStrategy
- Inherits:
-
GeneralStrategy
- Object
- GeneralStrategy
- ContentCheckerStrategy
- Defined in:
- lib/burnspam/point_tracker.rb
Overview
A specialized strategy for analizing the content field.
- Version
-
0.1.1
- Date
-
2011/12/18
- @author
-
Brian Burns, x10205284
- @reference
Constant Summary collapse
- @@recent_posts =
["5", "4", "3" , "2", "1"]
Instance Method Summary collapse
- #count_urls ⇒ Object
-
#duplicate? ⇒ Boolean
Compares a comment with recent comments and if a match is found returns true.
-
#initialize(content) ⇒ ContentCheckerStrategy
constructor
Stores content, URLS and individual words.
- #length ⇒ Object
-
#starts_with? ⇒ Boolean
Checks for (currently 2) keywords that we don’t like.
-
#url_length ⇒ Object
Calculate the average length of all URLs in content.
Methods inherited from GeneralStrategy
Constructor Details
#initialize(content) ⇒ ContentCheckerStrategy
Stores content, URLS and individual words
223 224 225 226 227 |
# File 'lib/burnspam/point_tracker.rb', line 223 def initialize(content) @content = content @urls = URI.extract(content) @keywords = @content.split /[\s,']+/ end |
Instance Method Details
#count_urls ⇒ Object
229 230 231 |
# File 'lib/burnspam/point_tracker.rb', line 229 def count_urls @urls.count end |
#duplicate? ⇒ Boolean
Compares a comment with recent comments and if a match is found returns true. Otherwise removes the oldest comment from the end and adds new one to the front (First In First Out queue)
265 266 267 268 269 270 271 272 273 274 |
# File 'lib/burnspam/point_tracker.rb', line 265 def duplicate? @@recent_posts.each do |comment| if comment == @content return true end end @@recent_posts.pop @@recent_posts.unshift @content return false end |
#length ⇒ Object
246 247 248 |
# File 'lib/burnspam/point_tracker.rb', line 246 def length @content.length end |
#starts_with? ⇒ Boolean
Checks for (currently 2) keywords that we don’t like
251 252 253 254 255 256 257 258 259 |
# File 'lib/burnspam/point_tracker.rb', line 251 def starts_with? if @content =~ /Cool(.*)/ return true elsif @content =~ /Wow(.*)/ return true else return false end end |
#url_length ⇒ Object
Calculate the average length of all URLs in content
234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/burnspam/point_tracker.rb', line 234 def url_length unless @urls.empty? @total_length = 0 @urls.each do |x| @total_length += x.length end @total_length / @urls.size else 0 end end |