class RPath::Where
Given a prior expression producing vertex array A, evaluates to an array containing the vertices in A that match certain conditions.
Public Class Methods
new(prior, conditions = {}, &selector)
click to toggle source
@overload initialize(prior, conditions)
@param [Expression] prior An expression that evaluates to a vertex array @param [Hash{Symbol => Object}] conditions A map of attribute keys to values.
@overload initialize(prior)
@param [Expression] prior An expression that evaluates to a vertex array @yieldparam vertex [Object] @yieldreturn [Boolean] Whether the vertex should be selected
Calls superclass method
# File lib/rpath/expressions.rb, line 222 def initialize(prior, conditions = {}, &selector) super() @prior = prior @selector = block_given? ? selector : nil @conditions = block_given? ? nil : conditions end
Public Instance Methods
to_s()
click to toggle source
@return [String]
# File lib/rpath/expressions.rb, line 230 def to_s conditions = @selector ? 'selector' : @conditions.map { |k, v| "#{k}: #{v}" }.join(', ') "#{@prior}[#{conditions}]" end
Private Instance Methods
do_eval(graph, adapter)
click to toggle source
# File lib/rpath/expressions.rb, line 240 def do_eval(graph, adapter) vertices = @prior.eval(graph, adapter) return nil unless vertices if @selector vertices.select(&@selector) else vertices.select do |vertex| @conditions.all? do |name, value| adapter.attribute(vertex, name) == value end end end end