Class: Cadenza::FilterNode
- Inherits:
-
Object
- Object
- Cadenza::FilterNode
- Defined in:
- lib/cadenza/nodes/filter_node.rb
Overview
The FilterNode is a node which contains the definition for a variable filter along with any parameters it is defined with.
Instance Attribute Summary collapse
-
#identifier ⇒ String
The name of the filter.
-
#parameters ⇒ Array
A list of parameter nodes given to the filter.
Instance Method Summary collapse
-
#==(rhs) ⇒ Boolean
True if the given filter node is equivalent by value to this node.
-
#evaluate(context, value) ⇒ Object
evaluates the filter with the given context and input value and returns the output of the evaluation.
-
#implied_globals ⇒ Array
A list of implied global variable names for this node.
-
#initialize(identifier, parameters = []) ⇒ FilterNode
constructor
constructs a new FilterNode with the given identifier and parameters.
Constructor Details
#initialize(identifier, parameters = []) ⇒ FilterNode
constructs a new Cadenza::FilterNode with the given identifier and parameters
15 16 17 18 |
# File 'lib/cadenza/nodes/filter_node.rb', line 15 def initialize(identifier, parameters=[]) @identifier = identifier @parameters = parameters end |
Instance Attribute Details
#identifier ⇒ String
Returns the name of the filter.
7 8 9 |
# File 'lib/cadenza/nodes/filter_node.rb', line 7 def identifier @identifier end |
#parameters ⇒ Array
Returns a list of parameter nodes given to the filter.
10 11 12 |
# File 'lib/cadenza/nodes/filter_node.rb', line 10 def parameters @parameters end |
Instance Method Details
#==(rhs) ⇒ Boolean
Returns true if the given filter node is equivalent by value to this node.
23 24 25 26 |
# File 'lib/cadenza/nodes/filter_node.rb', line 23 def ==(rhs) @identifier == rhs.identifier and @parameters == rhs.parameters end |
#evaluate(context, value) ⇒ Object
evaluates the filter with the given context and input value and returns the output of the evaluation.
39 40 41 |
# File 'lib/cadenza/nodes/filter_node.rb', line 39 def evaluate(context, value) context.evaluate_filter(@identifier, value, @parameters.map {|x| x.eval(context) }) end |
#implied_globals ⇒ Array
Returns a list of implied global variable names for this node.
29 30 31 |
# File 'lib/cadenza/nodes/filter_node.rb', line 29 def implied_globals @parameters.map(&:implied_globals).flatten.uniq end |