Class: FEEL::Node
- Inherits:
-
Treetop::Runtime::SyntaxNode
- Object
- Treetop::Runtime::SyntaxNode
- FEEL::Node
- Defined in:
- lib/feel/nodes.rb
Direct Known Subclasses
AtLiteral, BacktickName, BooleanLiteral, ClosedIntervalEnd, ClosedIntervalStart, Comparison, ComparisonOperator, Conjunction, Context, ContextEntry, ContextEntryList, DateTimeLiteral, Disjunction, Exponentiation, FilterExpression, FormalParameter, FunctionDefinition, FunctionInvocation, IfExpression, InstanceOf, Interval, List, ListEntries, Name, NullLiteral, NumericLiteral, OpenIntervalEnd, OpenIntervalStart, PositionalParameters, QualifiedName, QuantifiedExpression, SimpleExpressions, SimplePositiveUnaryTest, SimplePositiveUnaryTests, SimpleUnaryTests
Instance Method Summary collapse
- #access_property(result, property_name) ⇒ Object
-
#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
#access_property(result, property_name) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/feel/nodes.rb', line 22 def access_property(result, property_name) case result when DateTime case property_name when "year" then result.year when "month" then result.month when "day" then result.day when "weekday" then result.cwday when "hour" then result.hour when "minute" then result.min when "second" then result.sec end when Date case property_name when "year" then result.year when "month" then result.month when "day" then result.day when "weekday" then result.cwday end when Time case property_name when "hour" then result.hour when "minute" then result.min when "second" then result.sec when "time offset" then result.utc_offset when "timezone" then result.zone end when ActiveSupport::Duration case property_name when "years" then result.parts[:years] || 0 when "months" then result.parts[:months] || 0 when "days" then result.parts[:days] || 0 when "hours" then result.parts[:hours] || 0 when "minutes" then result.parts[:minutes] || 0 when "seconds" then result.parts[:seconds] || 0 end when Hash if result.key?(property_name.to_sym) result[property_name.to_sym] else result[property_name] end end end |
#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/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
67 68 69 70 71 72 73 |
# File 'lib/feel/nodes.rb', line 67 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 |