Class: Kotoshu::Spellchecker::FluentChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/kotoshu/fluent_checker.rb

Overview

Fluent checker for chainable configuration.

Provides a convenient API for spell checking with method chaining.

Examples:

Basic usage

result = Kotoshu.fluent.check("Hello wrold")

With options

Kotoshu.fluent
  .ignore_words(/https?:\/\/\S+/)
  .max_suggestions(5)
  .check("Hello wrold")

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spellchecker:, options: {}) ⇒ FluentChecker

Create a new fluent checker.

Parameters:

  • spellchecker (Spellchecker)

    The underlying spellchecker

  • options (Hash) (defaults to: {})

    Configuration options



28
29
30
31
32
33
# File 'lib/kotoshu/fluent_checker.rb', line 28

def initialize(spellchecker:, options: {})
  @spellchecker = spellchecker
  @options = options
  @progress_callback = nil
  @error_callback = nil
end

Instance Attribute Details

#optionsHash (readonly)

Returns Configuration options.

Returns:

  • (Hash)

    Configuration options



22
23
24
# File 'lib/kotoshu/fluent_checker.rb', line 22

def options
  @options
end

#spellcheckerSpellchecker (readonly)

Returns The underlying spellchecker.

Returns:



19
20
21
# File 'lib/kotoshu/fluent_checker.rb', line 19

def spellchecker
  @spellchecker
end

Instance Method Details

#check(text) ⇒ Models::Result::DocumentResult

Check text for spelling errors.

Parameters:

  • text (String)

    Text to check

Returns:



39
40
41
# File 'lib/kotoshu/fluent_checker.rb', line 39

def check(text)
  @spellchecker.check(text)
end

#ignore_words(pattern) ⇒ FluentChecker

Ignore words matching pattern.

Examples:

fluent.ignore_words(/https?:\/\/\S+/)

Parameters:

  • pattern (Regexp)

    Pattern to ignore

Returns:



50
51
52
53
54
# File 'lib/kotoshu/fluent_checker.rb', line 50

def ignore_words(pattern)
  @options[:ignore_patterns] ||= []
  @options[:ignore_patterns] << pattern
  self
end

#max_suggestions(max) ⇒ FluentChecker

Set maximum suggestions.

Parameters:

  • max (Integer)

    Maximum suggestions

Returns:



60
61
62
63
# File 'lib/kotoshu/fluent_checker.rb', line 60

def max_suggestions(max)
  @options[:max_suggestions] = max
  self
end

#on_error(&block) ⇒ FluentChecker

Set error callback.

Parameters:

  • block (Proc)

    Callback proc

Returns:



78
79
80
81
# File 'lib/kotoshu/fluent_checker.rb', line 78

def on_error(&block)
  @error_callback = block
  self
end

#on_progress(&block) ⇒ FluentChecker

Set progress callback.

Parameters:

  • block (Proc)

    Callback proc

Returns:



69
70
71
72
# File 'lib/kotoshu/fluent_checker.rb', line 69

def on_progress(&block)
  @progress_callback = block
  self
end

#resultModels::Result::ResultDocumentResult

Get the result.

Returns:

  • (Models::Result::ResultDocumentResult)

    Check result



86
87
88
# File 'lib/kotoshu/fluent_checker.rb', line 86

def result
  check(@text)
end