Class: SpamHam

Inherits:
Object
  • Object
show all
Defined in:
lib/spamham.rb,
lib/spamham/link.rb,
lib/spamham/scan.rb,
lib/spamham/version.rb,
lib/spamham/wordlist.rb,
lib/spamham/configure.rb

Defined Under Namespace

Classes: Link

Constant Summary collapse

VERSION =
"0.1.0"

Instance Method Summary collapse

Constructor Details

#initializeSpamHam

Returns a new instance of SpamHam.



7
8
9
# File 'lib/spamham.rb', line 7

def initialize
	self.conf
end

Instance Method Details

#conf(config = nil) ⇒ Object



2
3
4
5
6
7
8
# File 'lib/spamham/configure.rb', line 2

def conf(config = nil)
	@config = config || {}
	load_config_from_defaults
	if File.exist?("config/spamham.rb")
		load_config_from_file
	end
end

#scanObject



2
3
4
5
6
# File 'lib/spamham/scan.rb', line 2

def scan
	@string_weight = 0
	build_link_weights
	build_word_list_weights
end

#spam?(string) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
# File 'lib/spamham.rb', line 11

def spam?(string)
	@string=string
	self.scan
	@string=nil
	@string_weight >= @config[:trigger_weight]
end

#weightObject



18
19
20
# File 'lib/spamham.rb', line 18

def weight
	@string_weight
end

#wordlistObject



2
3
4
# File 'lib/spamham/wordlist.rb', line 2

def wordlist
	YAML.load_file(File.dirname(__FILE__) + "/wordlist.yml")["words"] + (@config[:additional_words] || [])
end