Class: Cadenza::FilterNode

Inherits:
Object
  • Object
show all
Includes:
TreeNode
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

Instance Method Summary collapse

Methods included from TreeNode

#to_tree

Constructor Details

#initialize(identifier, parameters = []) ⇒ FilterNode

constructs a new Cadenza::FilterNode with the given identifier and parameters

Parameters:

  • identifier (String)

    the name of the filter

  • parameters (Array) (defaults to: [])

    the parameters given to the filter


17
18
19
20
# File 'lib/cadenza/nodes/filter_node.rb', line 17

def initialize(identifier, parameters=[])
   @identifier = identifier
   @parameters = parameters
end

Instance Attribute Details

#identifierString

Returns the name of the filter.

Returns:

  • (String)

    the name of the filter


9
10
11
# File 'lib/cadenza/nodes/filter_node.rb', line 9

def identifier
  @identifier
end

#parametersArray

Returns a list of parameter nodes given to the filter.

Returns:

  • (Array)

    a list of parameter nodes given to the filter


12
13
14
# File 'lib/cadenza/nodes/filter_node.rb', line 12

def parameters
  @parameters
end

Instance Method Details

#==(rhs) ⇒ Boolean

Returns true if the given filter node is equivalent by value to this node.

Parameters:

Returns:

  • (Boolean)

    true if the given filter node is equivalent by value to this node.


25
26
27
28
# File 'lib/cadenza/nodes/filter_node.rb', line 25

def ==(rhs)
   @identifier == rhs.identifier &&
   @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.

Parameters:

  • context (Context)

    the context to evaluate with

  • value (String)

    the input value to filter

Returns:

  • the input value when passed through this evaluated filter


41
42
43
# File 'lib/cadenza/nodes/filter_node.rb', line 41

def evaluate(context, value)
   context.evaluate_filter(@identifier, value, @parameters.map {|x| x.eval(context) })
end

#implied_globalsArray

Returns a list of implied global variable names for this node.

Returns:

  • (Array)

    a list of implied global variable names for this node


31
32
33
# File 'lib/cadenza/nodes/filter_node.rb', line 31

def implied_globals
   @parameters.map(&:implied_globals).flatten.uniq
end