module Spellchecker::Utils

Constants

CONTEXT_LENGTH
CONTEXT_PART_LENGTH
QUOTE_REPLACE
SUFFIX_REGEXP

Public Instance Methods

fetch_context(text, position) click to toggle source

@param text [String] @param position [Integer] @return [String]

# File lib/spellchecker/utils.rb, line 16
def fetch_context(text, position)
  start_from = [position - CONTEXT_PART_LENGTH, 0].max
  end_at = position + CONTEXT_PART_LENGTH

  context = text[start_from..end_at].strip
  context = context.sub(/\A\w*?\W+/, '') if start_from != 0
  context = context.sub(/\W+\w*?\z/, '') if end_at < text.length

  context.strip
end
remove_suffix(string) click to toggle source

@param string [String] @return [String]

# File lib/spellchecker/utils.rb, line 35
def remove_suffix(string)
  string.sub(SUFFIX_REGEXP, '')
end
replace_quote(string) click to toggle source

@param string [String] @return [String]

# File lib/spellchecker/utils.rb, line 29
def replace_quote(string)
  string.tr(QUOTE_REPLACE, "'")
end