Class: Kotoshu::Algorithms::Suggest::Suggestion

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

Overview

Represents a single word suggestion.

Suggestions are produced internally to store enough information to make sure it is a good one.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, kind) ⇒ Suggestion

Returns a new instance of Suggestion.



37
38
39
40
# File 'lib/kotoshu/algorithms/suggest.rb', line 37

def initialize(text, kind)
  @text = text
  @kind = kind
end

Instance Attribute Details

#kindString (readonly)

Returns How suggestion was produced (same as method name).

Returns:

  • (String)

    How suggestion was produced (same as method name)



35
36
37
# File 'lib/kotoshu/algorithms/suggest.rb', line 35

def kind
  @kind
end

#textString (readonly)

Returns Actual suggestion text.

Returns:

  • (String)

    Actual suggestion text



32
33
34
# File 'lib/kotoshu/algorithms/suggest.rb', line 32

def text
  @text
end

Instance Method Details

#inspectString

Inspect string.

Returns:

  • (String)


63
64
65
# File 'lib/kotoshu/algorithms/suggest.rb', line 63

def inspect
  "Suggestion[#{@kind}](#{@text.inspect})"
end

#replace(**changes) ⇒ Suggestion

Create a copy with changes.

Parameters:

  • changes (Hash)

    Changes to apply

Returns:

  • (Suggestion)

    New suggestion with changes applied



46
47
48
49
50
51
# File 'lib/kotoshu/algorithms/suggest.rb', line 46

def replace(**changes)
  self.class.new(
    changes.fetch(:text, @text),
    changes.fetch(:kind, @kind)
  )
end

#to_sString

String representation.

Returns:

  • (String)


56
57
58
# File 'lib/kotoshu/algorithms/suggest.rb', line 56

def to_s
  @text
end