Class: Ldpath::TestSelector

Inherits:
Selector show all
Defined in:
lib/ldpath/tests.rb

Direct Known Subclasses

AndTest, IsTest, LanguageTest, NotTest, OrTest, TypeTest

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Selector

#loading

Constructor Details

#initialize(delegate = nil, test = nil) ⇒ TestSelector

Returns a new instance of TestSelector.



7
8
9
10
11
12
# File 'lib/ldpath/tests.rb', line 7

def initialize(delegate = nil, test = nil)
  @delegate = delegate
  @test = test

  super
end

Instance Attribute Details

#delegateObject (readonly)

Returns the value of attribute delegate.



5
6
7
# File 'lib/ldpath/tests.rb', line 5

def delegate
  @delegate
end

#testObject (readonly)

Returns the value of attribute test.



5
6
7
# File 'lib/ldpath/tests.rb', line 5

def test
  @test
end

Instance Method Details

#evaluate(program, uris, context) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ldpath/tests.rb', line 14

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

  entries = delegate.evaluate program, uris, context
  entries.select do |uri|
    result = enum_wrap(test.evaluate(program, uri, context)).any? do |x|
      x
    end
    yield uri if result
  end
end