Class: Swearjar::Tester

Inherits:
Object
  • Object
show all
Defined in:
lib/swearjar/tester.rb

Instance Method Summary collapse

Constructor Details

#initialize(config_file) ⇒ Tester

Returns a new instance of Tester.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/swearjar/tester.rb', line 8

def initialize(config_file)
  data = YAML.load_file

  @tester = FuzzyHash.new

  data['regex'].each do |pattern, type|
    @tester[Regexp.new(pattern)] = type
  end

  data['simple'].each do |test, type|
    @tester[test] = type
  end

end

Instance Method Details

#profane?(string) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/swearjar/tester.rb', line 27

def profane?(string)
  scan(string) {|w| return true}
end

#scan(string, &block) ⇒ Object



23
24
25
# File 'lib/swearjar/tester.rb', line 23

def scan(string, &block)
  string.scan(/\b[\b]+\b/, &block)
end