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.
-
#logical? ⇒ Boolean
True if the function’s return value is a boolean.
-
#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.
11 12 13 14 15 16 17 18 |
# File 'lib/janeway/ast/function.rb', line 11 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.
9 10 11 |
# File 'lib/janeway/ast/function.rb', line 9 def body @body end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
9 10 11 |
# File 'lib/janeway/ast/function.rb', line 9 def parameters @parameters end |
Instance Method Details
#literal? ⇒ Boolean
True if the function’s return value is a literal
39 40 41 42 43 44 45 46 |
# File 'lib/janeway/ast/function.rb', line 39 def literal? case name when 'length', 'count', 'value' then true when 'search', 'match' then false else raise "Unknown jsonpath function #{name}" end end |
#logical? ⇒ Boolean
True if the function’s return value is a boolean
50 51 52 53 54 55 56 57 |
# File 'lib/janeway/ast/function.rb', line 50 def logical? case name when 'length', 'count', 'value' then false when 'search', 'match' then true else raise "Unknown jsonpath function #{name}" end end |
#singular_query? ⇒ Boolean
True if this is the root of a singular-query.
34 35 36 |
# File 'lib/janeway/ast/function.rb', line 34 def singular_query? true end |
#to_s ⇒ Object
20 21 22 |
# File 'lib/janeway/ast/function.rb', line 20 def to_s "#{name}(#{@parameters.join(',')})" end |
#tree(level) ⇒ Array
26 27 28 |
# File 'lib/janeway/ast/function.rb', line 26 def tree(level) [indented(level, to_s)] end |