Class: CSDL::Builder
Overview
Builder is a class used to produce AST::Node objects built to be processed by any one of Processor, InteractionFilterProcessor, or QueryFilterProcessor.
Instance Method Summary collapse
-
#_and(&block) ⇒ AST::Node
Logically AND two or more child nodes together.
-
#_not(target, operator, argument = nil) ⇒ AST::Node
Negate a condition.
-
#_or(&block) ⇒ AST::Node
Logically OR two or more child nodes together.
-
#_return(&block) ⇒ AST::Node
Wrap child nodes in a return statement scope.
-
#condition(target, operator, argument = nil) ⇒ AST::Node
Create a “target + operator[ + argument]” CSDL condition.
-
#logical_group(logical_operator = nil, &block) ⇒ AST::Node
Wrap any child nodes in a logical grouping with parentheses.
-
#raw(raw_csdl) ⇒ AST::Node
Create a node to store raw CSDL.
-
#root(&block) ⇒ AST::Node
Wrap child nodes in a root node.
-
#statement_scope(&block) ⇒ AST::Node
Wrap child nodes in braces.
-
#tag(tag_class, &block) ⇒ AST::Node
Wrap child nodes in a VEDO tag classification.
-
#tag_tree(tag_namespaces, tag_class, &block) ⇒ AST::Node
Wrap child nodes in a VEDO tag classification tree.
Instance Method Details
#_and(&block) ⇒ AST::Node
Logically AND two or more child nodes together. Does not implicitly create a logical group with parentheses. If you want to logically group the ANDs, see #logical_group.
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/csdl/builder.rb', line 41 def _and(&block) children = __one_or_more_child_nodes(&block) if children.empty? nil elsif children.size == 1 children.first else s(:and, *children) end end |
#_not(target, operator, argument = nil) ⇒ AST::Node
Negate a condition. Analogous to #condition with NOT prepended to the condition.
75 76 77 78 |
# File 'lib/csdl/builder.rb', line 75 def _not(target, operator, argument = nil) node = condition(target, operator, argument) node.updated(:not) end |
#_or(&block) ⇒ AST::Node
Logically OR two or more child nodes together. Does not implicitly create a logical group with parentheses. If you want to logically group the ORs, see #logical_group.
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/csdl/builder.rb', line 98 def _or(&block) children = __one_or_more_child_nodes(&block) if children.empty? nil elsif children.size == 1 children.first else s(:or, *children) end end |
#_return(&block) ⇒ AST::Node
The base Processor will not process return statement nodes, use InteractionFilterProcessor instead.
Wrap child nodes in a return statement scope.
126 127 128 |
# File 'lib/csdl/builder.rb', line 126 def _return(&block) s(:return, statement_scope(&block)) end |
#condition(target, operator, argument = nil) ⇒ AST::Node
Create a “target + operator[ + argument]” CSDL condition. This method is the workhorse of any CSDL Filter. See #_not if you wish to negate a single condition.
154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/csdl/builder.rb', line 154 def condition(target, operator, argument = nil) target_node = s(:target, target) operator_node = s(:operator, operator) argument_node = nil unless argument.nil? argument_node_type = argument.class.name.to_s.downcase.to_sym child_argument_node = s(argument_node_type, argument) argument_node = s(:argument, child_argument_node) end s(:condition, *[target_node, operator_node, argument_node].compact) end |
#logical_group(logical_operator = nil, &block) ⇒ AST::Node
231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/csdl/builder.rb', line 231 def logical_group(logical_operator = nil, &block) children = __one_or_more_child_nodes(&block) if children.empty? nil elsif logical_operator.nil? || children.size == 1 s(:logical_group, *children) else s(:logical_group, s(logical_operator, *children)) end end |
#raw(raw_csdl) ⇒ AST::Node
this method will not implicitly wrap the raw CSDL in any grouping or scope.
Create a node to store raw CSDL.
263 264 265 |
# File 'lib/csdl/builder.rb', line 263 def raw(raw_csdl) s(:raw, raw_csdl.to_s) end |
#root(&block) ⇒ AST::Node
Wrap child nodes in a root node. Useful for building CSDL with tagging and a return statement.
295 296 297 298 299 300 301 302 |
# File 'lib/csdl/builder.rb', line 295 def root(&block) children = __one_or_more_child_nodes(&block) if children.empty? nil else s(:root, *children) end end |
#statement_scope(&block) ⇒ AST::Node
The base Processor will not process statement_scope nodes, use InteractionFilterProcessor instead.
Wrap child nodes in braces. @note Generally not useful on its own, see #_return, #tag, or #tag_tree usage.
323 324 325 326 327 328 329 330 |
# File 'lib/csdl/builder.rb', line 323 def statement_scope(&block) children = __one_or_more_child_nodes(&block) if children.empty? nil else s(:statement_scope, *children) end end |
#tag(tag_class, &block) ⇒ AST::Node
The base Processor will not process tag nodes, use InteractionFilterProcessor instead.
Wrap child nodes in a VEDO tag classification.
351 352 353 354 355 356 |
# File 'lib/csdl/builder.rb', line 351 def tag(tag_class, &block) s(:tag, s(:tag_class, s(:string, tag_class)), statement_scope(&block)) end |
#tag_tree(tag_namespaces, tag_class, &block) ⇒ AST::Node
The base Processor will not process tag_tree nodes, use InteractionFilterProcessor instead.
Wrap child nodes in a VEDO tag classification tree.
378 379 380 381 382 383 384 385 386 387 388 389 |
# File 'lib/csdl/builder.rb', line 378 def tag_tree(tag_namespaces, tag_class, &block) tag_namespace_nodes = tag_namespaces.map do |tag_namespace| s(:tag_namespace, tag_namespace) end s(:tag, s(:tag_namespaces, *tag_namespace_nodes), s(:tag_class, s(:string, tag_class)), statement_scope(&block)) end |