Class: Cadenza::FilteredValueNode

Inherits:
Object
  • Object
show all
Includes:
TreeNode
Defined in:
lib/cadenza/nodes/filtered_value_node.rb

Overview

The FilteredValueNode applies a list of passed FilterNode to it's value when evaluated.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TreeNode

#to_tree

Constructor Details

#initialize(value, filters = []) ⇒ FilteredValueNode

Parameters:

  • identifier (String)

    see #identifier

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

    see #filters


18
19
20
21
# File 'lib/cadenza/nodes/filtered_value_node.rb', line 18

def initialize(value, filters=[])
   @value = value
   @filters = filters
end

Instance Attribute Details

#filtersArray

Returns a list of Cadenza::FilterNode to evaluate the value with, once the value has itself been evaluated.

Returns:

  • (Array)

    a list of Cadenza::FilterNode to evaluate the value with, once the value has itself been evaluated.


13
14
15
# File 'lib/cadenza/nodes/filtered_value_node.rb', line 13

def filters
  @filters
end

#valueNode

Returns the value to be filtered.

Returns:

  • (Node)

    the value to be filtered


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

def value
  @value
end

Instance Method Details

#==(rhs) ⇒ Boolean

Returns if the given Cadenza::FilteredValueNode is equivalent by value to this node.

Parameters:

Returns:


43
44
45
# File 'lib/cadenza/nodes/filtered_value_node.rb', line 43

def ==(rhs)
   self.value == rhs.value && self.filters == rhs.filters
end

#eval(context) ⇒ Object

Returns gets the value and returns it after being passed through all filters.

Parameters:

Returns:

  • (Object)

    gets the value and returns it after being passed through all filters


32
33
34
35
36
37
38
# File 'lib/cadenza/nodes/filtered_value_node.rb', line 32

def eval(context)
   value = @value.eval(context)

   @filters.each {|filter| value = filter.evaluate(context, value) }

   value
end

#implied_globalsArray

Returns a list of names which are implied to be global variables from this node.

Returns:

  • (Array)

    a list of names which are implied to be global variables from this node.


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

def implied_globals
   (@value.implied_globals + @filters.map(&:implied_globals).flatten).uniq
end