Class: Kotoshu::Algorithms::Suggest::MultiWordSuggestion

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

Overview

Represents suggestion to split words into several.

Used when the algorithm suggests that a misspelled word should be split into multiple dictionary words.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(words, source, allow_dash: true) ⇒ MultiWordSuggestion

Returns a new instance of MultiWordSuggestion.



82
83
84
85
86
# File 'lib/kotoshu/algorithms/suggest.rb', line 82

def initialize(words, source, allow_dash: true)
  @words = words
  @source = source
  @allow_dash = allow_dash
end

Instance Attribute Details

#allow_dashBoolean (readonly)

Returns Whether words can be joined by dash.

Returns:

  • (Boolean)

    Whether words can be joined by dash



80
81
82
# File 'lib/kotoshu/algorithms/suggest.rb', line 80

def allow_dash
  @allow_dash
end

#sourceString (readonly)

Returns Same as Suggestion.kind.

Returns:

  • (String)

    Same as Suggestion.kind



77
78
79
# File 'lib/kotoshu/algorithms/suggest.rb', line 77

def source
  @source
end

#wordsArray<String> (readonly)

Returns List of words.

Returns:

  • (Array<String>)

    List of words



74
75
76
# File 'lib/kotoshu/algorithms/suggest.rb', line 74

def words
  @words
end

Instance Method Details

#inspectString

Inspect string.

Returns:

  • (String)


99
100
101
# File 'lib/kotoshu/algorithms/suggest.rb', line 99

def inspect
  "Suggestion[#{@source}](#{@words.inspect})"
end

#stringify(separator = ' ') ⇒ Suggestion

Convert to string suggestion.

Parameters:

  • separator (String) (defaults to: ' ')

    Separator to join words with

Returns:

  • (Suggestion)

    String suggestion with joined words



92
93
94
# File 'lib/kotoshu/algorithms/suggest.rb', line 92

def stringify(separator = ' ')
  Suggestion.new(@words.join(separator), @source)
end