class Samovar::Completion::Suggestion
A single completion suggestion.
Attributes
@attribute [String | Nil] The completion description.
@attribute [Hash] Additional completion metadata.
@attribute [Object] The completion value.
Public Class Methods
# File vendor/bundle/ruby/4.0.0/gems/samovar-2.5.1/lib/samovar/completion/suggestion.rb, line 35 def initialize(value, type: nil, description: nil, **options) @type = type @value = value @description = description @options = options end
Initialize a new completion suggestion.
@parameter value [Object] The completion value. @parameter type [Symbol | String | Nil] The completion type. @parameter description [String | Nil] The completion description. @parameter options [Hash] Additional completion metadata.
Source
# File vendor/bundle/ruby/4.0.0/gems/samovar-2.5.1/lib/samovar/completion/suggestion.rb, line 14 def self.wrap(value) case value when self return value when Hash value = value.dup suggestion = value.fetch(:value) value.delete(:value) return self.new(suggestion, **value) else return self.new(value) end end
Wrap a raw completion value in a suggestion.
@parameter value [Suggestion | Hash | Object] The value to wrap. @returns [Suggestion] The normalized suggestion.
Public Instance Methods
Source
# File vendor/bundle/ruby/4.0.0/gems/samovar-2.5.1/lib/samovar/completion/suggestion.rb, line 58 def start_with?(prefix) to_s.start_with?(prefix) end
Whether this suggestion starts with the given prefix.
@parameter prefix [String] The prefix to check. @returns [Boolean] True if the suggestion starts with the given prefix.
Source
# File vendor/bundle/ruby/4.0.0/gems/samovar-2.5.1/lib/samovar/completion/suggestion.rb, line 65 def to_record fields = [ escape(@type), escape(@value), escape(@description), ] @options.each do |key, value| next if value.nil? fields << "#{escape(key)}=#{escape(value)}" end return fields.join("\t") end
Convert the suggestion to a tab-separated completion record.
@returns [String] The escaped completion record.
Source
# File vendor/bundle/ruby/4.0.0/gems/samovar-2.5.1/lib/samovar/completion/suggestion.rb, line 83 def to_s @value.to_s end
Convert the suggestion to its value.
@returns [String] The suggestion value.