Class: StopForumSpam::Spammer

Inherits:
Object
  • Object
show all
Defined in:
lib/stop_forum_spam/spammer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ Spammer

Returns a new instance of Spammer.



8
9
10
11
12
13
14
# File 'lib/stop_forum_spam/spammer.rb', line 8

def initialize(id)
  @id         = id
  @type       = self.class.guess_type(id)
  @frequency  = response["frequency"]
  @last_seen  = response["lastseen"]
  @appears    = response['appears'] == 'yes' ? true : false
end

Instance Attribute Details

#appearsObject (readonly) Also known as: appears?

Returns the value of attribute appears.



3
4
5
# File 'lib/stop_forum_spam/spammer.rb', line 3

def appears
  @appears
end

#frequencyObject (readonly) Also known as: count

Returns the value of attribute frequency.



3
4
5
# File 'lib/stop_forum_spam/spammer.rb', line 3

def frequency
  @frequency
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/stop_forum_spam/spammer.rb', line 3

def id
  @id
end

#last_seenObject (readonly)

Returns the value of attribute last_seen.



3
4
5
# File 'lib/stop_forum_spam/spammer.rb', line 3

def last_seen
  @last_seen
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/stop_forum_spam/spammer.rb', line 3

def type
  @type
end

Class Method Details

.guess_type(id) ⇒ Object



20
21
22
23
24
# File 'lib/stop_forum_spam/spammer.rb', line 20

def self.guess_type(id)
  return 'ip' if id.match(/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/)
  return 'email' if id.match(/.*@.*/)
  return 'username'
end

.is_spammer?(id) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/stop_forum_spam/spammer.rb', line 16

def self.is_spammer?(id)
  new(id).appears?
end