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.



90
91
92
93
# File 'lib/ldpath/selectors.rb', line 90

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

Instance Attribute Details

#propertyObject (readonly)

Returns the value of attribute property.



89
90
91
# File 'lib/ldpath/selectors.rb', line 89

def property
  @property
end

#repeatObject (readonly)

Returns the value of attribute repeat.



89
90
91
# File 'lib/ldpath/selectors.rb', line 89

def repeat
  @repeat
end

Instance Method Details

#evaluate(program, uris, context) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/ldpath/selectors.rb', line 95

def evaluate(program, uris, context)
  result = []
  input = Array(uris)

  Range.new(0, repeat.min, true).each do
    input = property.evaluate program, input, context
  end

  repeat.each_with_index do |i, idx|
    break if input.empty? || idx > 25 # we're probably lost..
    input = property.evaluate program, input, context
    result |= input
  end
  result.flatten.compact
end