Class: SpotFeel::Node
- Inherits:
-
Treetop::Runtime::SyntaxNode
- Object
- Treetop::Runtime::SyntaxNode
- SpotFeel::Node
- Defined in:
- lib/spot_feel/nodes.rb
Direct Known Subclasses
Addition, BooleanLiteral, ClosedIntervalEnd, ClosedIntervalStart, Comparison, ComparisonOperator, Conjunction, Context, ContextEntry, ContextEntryList, DateTimeLiteral, Disjunction, Division, Exponentiation, FilterExpression, FormalParameter, FunctionDefinition, FunctionInvocation, IfExpression, InstanceOf, Interval, List, ListEntries, Multiplication, Name, NullLiteral, NumericLiteral, OpenIntervalEnd, OpenIntervalStart, PositionalParameters, QualifiedName, QuantifiedExpression, SimpleExpressions, SimplePositiveUnaryTest, SimplePositiveUnaryTests, SimpleUnaryTests, StringLiteral, Subtraction
Instance Method Summary collapse
-
#qualified_names_in_context(hash = {}, prefix = '', qualified_names = Set.new) ⇒ Object
Takes a context hash and returns an array of qualified names { “person”: { “name”: { “first”: “Eric”, “last”: “Carlson” }, “age”: 60 } } => [“person”, “person.name.first”, “person.name.last”, “person.age”].
- #raise_evaluation_error(missing_name, ctx = {}) ⇒ Object
Instance Method Details
#qualified_names_in_context(hash = {}, prefix = '', qualified_names = Set.new) ⇒ Object
Takes a context hash and returns an array of qualified names { “person”: { “name”: { “first”: “Eric”, “last”: “Carlson” }, “age”: 60 } } => [“person”, “person.name.first”, “person.name.last”, “person.age”]
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/spot_feel/nodes.rb', line 9 def qualified_names_in_context(hash = {}, prefix = '', qualified_names = Set.new) hash.each do |key, value| new_prefix = prefix.empty? ? "#{key}" : "#{prefix}.#{key}" if value.is_a?(Hash) qualified_names_in_context(value, new_prefix, qualified_names) else qualified_names.add(new_prefix) end end if hash qualified_names.to_a end |
#raise_evaluation_error(missing_name, ctx = {}) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/spot_feel/nodes.rb', line 22 def raise_evaluation_error(missing_name, ctx = {}) names = qualified_names_in_context(ctx) checker = DidYouMean::SpellChecker.new(dictionary: names) guess = checker.correct(missing_name) suffix = " Did you mean #{guess.first}?" unless guess.empty? raise EvaluationError.new("Identifier #{missing_name} not found.#{suffix}") end |