Class: Merimee::Checker

Inherits:
Object
  • Object
show all
Defined in:
lib/merimee/checker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = nil) {|@config| ... } ⇒ Checker

Returns a new instance of Checker.

Yields:


6
7
8
9
# File 'lib/merimee/checker.rb', line 6

def initialize(config = nil)
  @config = config || Config.new
  yield @config if block_given?
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config


5
6
7
# File 'lib/merimee/checker.rb', line 5

def config
  @config
end

Instance Method Details

#check(text, options = {}) ⇒ Object


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/merimee/checker.rb', line 11

def check(text, options = {})
  AfterTheDeadline.language = options[:language] || @config.language
  AfterTheDeadline.key = @config.api_key
  errors = AfterTheDeadline.check(text)
  
  # Remove spelling errors from our custom dictionary
  # Also remove stuff that is obviously not a word (AtD seems to have issues sometime)
  errors.reject! do |e|
    e.type == 'spelling' &&
      @config.dictionary.include?(e.string)
  end

  # Remove any error types we don't care about
  errors.each do |err|
    err.severity = @config.severity[err.description.downcase] || :error
  end

  errors
end