Class: Janeway::AST::Function
- Inherits:
-
Expression
- Object
- Expression
- Janeway::AST::Function
- Defined in:
- lib/janeway/ast/function.rb
Overview
Represents a JSONPath built-in function.
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
Attributes inherited from Expression
Instance Method Summary collapse
-
#initialize(name, parameters, &body) ⇒ Function
constructor
A new instance of Function.
-
#literal? ⇒ Boolean
True if the function’s return value is a literal.
-
#singular_query? ⇒ Boolean
True if this is the root of a singular-query.
- #to_s ⇒ Object
- #tree(level) ⇒ Array
Methods inherited from Expression
Constructor Details
#initialize(name, parameters, &body) ⇒ Function
Returns a new instance of Function.
13 14 15 16 17 18 19 20 |
# File 'lib/janeway/ast/function.rb', line 13 def initialize(name, parameters, &body) raise ArgumentError, "expect string, got #{name.inspect}" unless name.is_a?(String) super(name) @parameters = parameters @body = body raise "expect body to be a Proc, got #{body.class}" unless body.is_a?(Proc) end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
11 12 13 |
# File 'lib/janeway/ast/function.rb', line 11 def body @body end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
11 12 13 |
# File 'lib/janeway/ast/function.rb', line 11 def parameters @parameters end |
Instance Method Details
#literal? ⇒ Boolean
True if the function’s return value is a literal
41 42 43 44 45 46 47 48 |
# File 'lib/janeway/ast/function.rb', line 41 def literal? case name when 'length', 'count', 'value' then true when 'search', 'match' then false else raise "Unknown jsonpath function #{name}" end end |
#singular_query? ⇒ Boolean
True if this is the root of a singular-query.
36 37 38 |
# File 'lib/janeway/ast/function.rb', line 36 def singular_query? true end |
#to_s ⇒ Object
22 23 24 |
# File 'lib/janeway/ast/function.rb', line 22 def to_s "#{name}(#{@parameters.join(',')})" end |
#tree(level) ⇒ Array
28 29 30 |
# File 'lib/janeway/ast/function.rb', line 28 def tree(level) [indented(level, to_s)] end |