Class: Kotoshu::Suggestions::Context
- Inherits:
-
Object
- Object
- Kotoshu::Suggestions::Context
- Defined in:
- lib/kotoshu/suggestions/context.rb
Overview
Context object passed to suggestion strategies. Encapsulates the state and parameters for suggestion generation.
Instance Attribute Summary collapse
-
#dictionary ⇒ Object
readonly
Returns the value of attribute dictionary.
-
#max_results ⇒ Object
readonly
Returns the value of attribute max_results.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#word ⇒ Object
readonly
Returns the value of attribute word.
Instance Method Summary collapse
-
#has_option?(key) ⇒ Boolean
Check if an option is present.
-
#initialize(word:, dictionary:, max_results: 10, **options) ⇒ Context
constructor
A new instance of Context.
-
#inspect ⇒ String
(also: #to_s)
Inspect the context.
-
#option(key, default = nil) ⇒ Object
Get an option value.
-
#to_h ⇒ Hash
Convert context to hash.
Constructor Details
#initialize(word:, dictionary:, max_results: 10, **options) ⇒ Context
Returns a new instance of Context.
10 11 12 13 14 15 |
# File 'lib/kotoshu/suggestions/context.rb', line 10 def initialize(word:, dictionary:, max_results: 10, **) @word = word @dictionary = dictionary @max_results = max_results @options = end |
Instance Attribute Details
#dictionary ⇒ Object (readonly)
Returns the value of attribute dictionary.
8 9 10 |
# File 'lib/kotoshu/suggestions/context.rb', line 8 def dictionary @dictionary end |
#max_results ⇒ Object (readonly)
Returns the value of attribute max_results.
8 9 10 |
# File 'lib/kotoshu/suggestions/context.rb', line 8 def max_results @max_results end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/kotoshu/suggestions/context.rb', line 8 def @options end |
#word ⇒ Object (readonly)
Returns the value of attribute word.
8 9 10 |
# File 'lib/kotoshu/suggestions/context.rb', line 8 def word @word end |
Instance Method Details
#has_option?(key) ⇒ Boolean
Check if an option is present.
30 31 32 |
# File 'lib/kotoshu/suggestions/context.rb', line 30 def has_option?(key) @options.key?(key) end |
#inspect ⇒ String Also known as: to_s
Inspect the context.
49 50 51 |
# File 'lib/kotoshu/suggestions/context.rb', line 49 def inspect "Context(word: '#{@word}', max_results: #{@max_results})" end |
#option(key, default = nil) ⇒ Object
Get an option value.
22 23 24 |
# File 'lib/kotoshu/suggestions/context.rb', line 22 def option(key, default = nil) @options.fetch(key, default) end |
#to_h ⇒ Hash
Convert context to hash.
37 38 39 40 41 42 43 44 |
# File 'lib/kotoshu/suggestions/context.rb', line 37 def to_h { word: @word, dictionary: @dictionary, max_results: @max_results, options: @options } end |