Class: Samovar::Completion::Suggestion
- Inherits:
-
Object
- Object
- Samovar::Completion::Suggestion
- Defined in:
- lib/samovar/completion/suggestion.rb
Overview
A single completion suggestion.
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
- #The completion description.(completiondescription.) ⇒ Object readonly
- #The completion type.(completiontype.) ⇒ Object readonly
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
-
.wrap(value) ⇒ Object
Wrap a raw completion value in a suggestion.
Instance Method Summary collapse
- #Additional completion metadata.=(completionmetadata. = (value)) ⇒ Object
-
#initialize(value, type: nil, description: nil, **options) ⇒ Suggestion
constructor
Initialize a new completion suggestion.
-
#start_with?(prefix) ⇒ Boolean
Whether this suggestion starts with the given prefix.
- #The completion value.=(completionvalue. = (value)) ⇒ Object
-
#to_record ⇒ Object
Convert the suggestion to a tab-separated completion record.
-
#to_s ⇒ Object
Convert the suggestion to its value.
Constructor Details
#initialize(value, type: nil, description: nil, **options) ⇒ Suggestion
Initialize a new completion suggestion.
35 36 37 38 39 40 |
# File 'lib/samovar/completion/suggestion.rb', line 35 def initialize(value, type: nil, description: nil, **) @type = type @value = value @description = description @options = end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
49 50 51 |
# File 'lib/samovar/completion/suggestion.rb', line 49 def description @description end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
52 53 54 |
# File 'lib/samovar/completion/suggestion.rb', line 52 def @options end |
#The completion description.(completiondescription.) ⇒ Object (readonly)
49 |
# File 'lib/samovar/completion/suggestion.rb', line 49 attr :description |
#The completion type.(completiontype.) ⇒ Object (readonly)
43 |
# File 'lib/samovar/completion/suggestion.rb', line 43 attr :type |
#type ⇒ Object (readonly)
Returns the value of attribute type.
43 44 45 |
# File 'lib/samovar/completion/suggestion.rb', line 43 def type @type end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
46 47 48 |
# File 'lib/samovar/completion/suggestion.rb', line 46 def value @value end |
Class Method Details
.wrap(value) ⇒ Object
Wrap a raw completion value in a suggestion.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File '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 |
Instance Method Details
#Additional completion metadata.=(completionmetadata. = (value)) ⇒ Object
52 |
# File 'lib/samovar/completion/suggestion.rb', line 52 attr :options |
#start_with?(prefix) ⇒ Boolean
Whether this suggestion starts with the given prefix.
58 59 60 |
# File 'lib/samovar/completion/suggestion.rb', line 58 def start_with?(prefix) to_s.start_with?(prefix) end |
#The completion value.=(completionvalue. = (value)) ⇒ Object
46 |
# File 'lib/samovar/completion/suggestion.rb', line 46 attr :value |
#to_record ⇒ Object
Convert the suggestion to a tab-separated completion record.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File '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 |
#to_s ⇒ Object
Convert the suggestion to its value.
83 84 85 |
# File 'lib/samovar/completion/suggestion.rb', line 83 def to_s @value.to_s end |