Class: FEEL::Node
- Inherits:
-
Treetop::Runtime::SyntaxNode
- Object
- Treetop::Runtime::SyntaxNode
- FEEL::Node
show all
- Defined in:
- lib/feel/nodes.rb
Direct Known Subclasses
AtLiteral, BacktickName, BooleanLiteral, ClosedIntervalEnd, ClosedIntervalStart, Comparison, ComparisonOperator, Conjunction, Context, ContextEntry, ContextEntryList, DateTimeLiteral, Disjunction, Exponentiation, ExpressionUnaryTest, 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
Instance Method Details
#access_property(result, property_name) ⇒ Object
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
66
67
68
69
70
71
72
|
# File 'lib/feel/nodes.rb', line 29
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
|
5
6
7
8
9
10
|
# File 'lib/feel/nodes.rb', line 5
def contains_input_placeholder?
return true if is_a?(Name) && text_value == "?"
return false unless respond_to?(:elements) && elements
elements.any? { |el| el.respond_to?(:contains_input_placeholder?) && el.contains_input_placeholder? }
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”]
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/feel/nodes.rb', line 16
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
74
75
76
77
78
79
80
|
# File 'lib/feel/nodes.rb', line 74
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
|