Class: Cadenza::FilterNode

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

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



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

#identifierString

Returns the name of the filter.

Returns:

  • (String)

    the name of the filter



7
8
9
# File 'lib/cadenza/nodes/filter_node.rb', line 7

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



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.

Parameters:

Returns:

  • (Boolean)

    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.

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



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_globalsArray

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

Returns:

  • (Array)

    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