Class: Ldpath::FunctionSelector

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(fname, arguments = []) ⇒ FunctionSelector

Returns a new instance of FunctionSelector.



53
54
55
56
# File 'lib/ldpath/selectors.rb', line 53

def initialize(fname, arguments = [])
  @fname = fname
  @arguments = Array(arguments)
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



51
52
53
# File 'lib/ldpath/selectors.rb', line 51

def arguments
  @arguments
end

#fnameObject (readonly)

Returns the value of attribute fname.



51
52
53
# File 'lib/ldpath/selectors.rb', line 51

def fname
  @fname
end

Instance Method Details

#evaluate(program, uris, context) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/ldpath/selectors.rb', line 58

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

  enum_wrap(uris).map do |uri|
    loading program, uri, context
    args = arguments.map do |i|
      case i
      when Selector
        i.evaluate(program, uri, context)
      else
        i
      end
    end
    enum_flatten_one(program.func_call(fname, uri, context, *args)).each do |x|
      yield x unless x.nil?
    end
  end
end