Module: Spellchecker::Utils
- Defined in:
- lib/spellchecker/utils.rb
Constant Summary collapse
- CONTEXT_LENGTH =
140
- CONTEXT_PART_LENGTH =
CONTEXT_LENGTH / 2
- QUOTE_REPLACE =
'’`'
- SUFFIX_REGEXP =
/[’`']s?\z/.freeze
Class Method Summary collapse
- .fetch_context(text, position) ⇒ String
- .remove_suffix(string) ⇒ String
- .replace_quote(string) ⇒ String
Class Method Details
.fetch_context(text, position) ⇒ String
16 17 18 19 20 21 22 23 24 25 |
# 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) ⇒ String
35 36 37 |
# File 'lib/spellchecker/utils.rb', line 35 def remove_suffix(string) string.sub(SUFFIX_REGEXP, '') end |
.replace_quote(string) ⇒ String
29 30 31 |
# File 'lib/spellchecker/utils.rb', line 29 def replace_quote(string) string.tr(QUOTE_REPLACE, "'") end |