Class: Lutaml::Xml::Schema::Xsd::Errors::Suggestion
- Inherits:
-
Object
- Object
- Lutaml::Xml::Schema::Xsd::Errors::Suggestion
- Defined in:
- lib/lutaml/xml/schema/xsd/errors/suggestion.rb
Overview
Value object representing a suggestion for error resolution
Instance Attribute Summary collapse
-
#explanation ⇒ String
readonly
Explanation of the suggestion.
-
#similarity ⇒ Float
readonly
Similarity score (0.0 to 1.0).
-
#text ⇒ String
readonly
The suggestion text.
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer
Compare suggestions by similarity (higher is better).
-
#initialize(text:, similarity: 1.0, explanation: nil) ⇒ Suggestion
constructor
Initialize a suggestion.
-
#similarity_percentage ⇒ Integer
Get similarity percentage.
-
#to_h ⇒ Hash
Convert to hash.
Constructor Details
#initialize(text:, similarity: 1.0, explanation: nil) ⇒ Suggestion
Initialize a suggestion
31 32 33 34 35 |
# File 'lib/lutaml/xml/schema/xsd/errors/suggestion.rb', line 31 def initialize(text:, similarity: 1.0, explanation: nil) @text = text @similarity = similarity.to_f @explanation = explanation || "Did you mean '#{text}'?" end |
Instance Attribute Details
#explanation ⇒ String (readonly)
Returns Explanation of the suggestion.
24 25 26 |
# File 'lib/lutaml/xml/schema/xsd/errors/suggestion.rb', line 24 def explanation @explanation end |
#similarity ⇒ Float (readonly)
Returns Similarity score (0.0 to 1.0).
21 22 23 |
# File 'lib/lutaml/xml/schema/xsd/errors/suggestion.rb', line 21 def similarity @similarity end |
#text ⇒ String (readonly)
Returns The suggestion text.
18 19 20 |
# File 'lib/lutaml/xml/schema/xsd/errors/suggestion.rb', line 18 def text @text end |
Instance Method Details
#<=>(other) ⇒ Integer
Compare suggestions by similarity (higher is better)
59 60 61 |
# File 'lib/lutaml/xml/schema/xsd/errors/suggestion.rb', line 59 def <=>(other) other.similarity <=> @similarity end |
#similarity_percentage ⇒ Integer
Get similarity percentage
40 41 42 |
# File 'lib/lutaml/xml/schema/xsd/errors/suggestion.rb', line 40 def similarity_percentage (@similarity * 100).round end |
#to_h ⇒ Hash
Convert to hash
47 48 49 50 51 52 53 |
# File 'lib/lutaml/xml/schema/xsd/errors/suggestion.rb', line 47 def to_h { text: @text, similarity: @similarity, explanation: @explanation, } end |