Class: Ldpath::RecursivePathSelector

Inherits:
Selector
  • Object
show all
Defined in:
lib/ldpath/selectors.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Selector

#loading

Constructor Details

#initialize(property, repeat) ⇒ RecursivePathSelector

Returns a new instance of RecursivePathSelector.



136
137
138
139
# File 'lib/ldpath/selectors.rb', line 136

def initialize(property, repeat)
  @property = property
  @repeat = repeat
end

Instance Attribute Details

#propertyObject (readonly)

Returns the value of attribute property.



135
136
137
# File 'lib/ldpath/selectors.rb', line 135

def property
  @property
end

#repeatObject (readonly)

Returns the value of attribute repeat.



135
136
137
# File 'lib/ldpath/selectors.rb', line 135

def repeat
  @repeat
end

Instance Method Details

#evaluate(program, uris, context) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/ldpath/selectors.rb', line 141

def evaluate(program, uris, context)
  return to_enum(:evaluate, program, uris, context) unless block_given?

  input = enum_wrap(uris)

  (0..repeat.max).each_with_index do |i, idx|
    break if input.none? || (repeat.max == Ldpath::Transform::Infinity && idx > 25) # we're probably lost..
    input = property.evaluate program, input, context

    next unless idx >= repeat.min

    enum_wrap(input).each do |x|
      yield x
    end
  end
end