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.



156
157
158
159
160
161
# File 'lib/ldpath/selectors.rb', line 156

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

  super
end

Instance Attribute Details

#propertyObject (readonly)

Returns the value of attribute property.



154
155
156
# File 'lib/ldpath/selectors.rb', line 154

def property
  @property
end

#repeatObject (readonly)

Returns the value of attribute repeat.



154
155
156
# File 'lib/ldpath/selectors.rb', line 154

def repeat
  @repeat
end

Instance Method Details

#evaluate(program, uris, context, &block) ⇒ Object



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/ldpath/selectors.rb', line 163

def evaluate(program, uris, context, &block)
  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(&block)
  end
end