Class: RDF::N3::Algebra::Str::Matches

Inherits:
ResourceOperator
  • Object
show all
Defined in:
lib/rdf/n3/algebra/str/matches.rb

Overview

The subject is a string; the object is is a regular expression in the perl, python style. It is true iff the string matches the regexp.

Direct Known Subclasses

NotMatches

Constant Summary collapse

NAME =
:strMatches
URI =
RDF::N3::Str.matches

Instance Attribute Summary

Attributes included from Enumerable

#existentials, #universals

Instance Method Summary collapse

Methods inherited from ResourceOperator

#as_literal, #execute, #valid?

Methods included from Builtin

#each, #evaluate, #hash, #rank, #to_uri

Instance Method Details

#apply(left, right) ⇒ RDF::Literal::Boolean

Tre if right, treated as a regular expression, matches left

Parameters:

Returns:

  • (RDF::Literal::Boolean)

    true or false

See Also:



33
34
35
# File 'lib/rdf/n3/algebra/str/matches.rb', line 33

def apply(left, right)
  RDF::Literal(Regexp.new(right.to_s).match?(left.to_s))
end

#input_operandObject

Neither subect nor object are considered inputs, and must be resolved before evaluation.



20
21
22
# File 'lib/rdf/n3/algebra/str/matches.rb', line 20

def input_operand
  RDF::N3::List.new
end

#resolve(resource, position:) ⇒ RDF::Literal

Resolves inputs as strings.

Parameters:

  • resource (RDF::Term)
  • position (:subject, :object)

Returns:

See Also:

  • ResourceOperator#evaluate


15
16
17
# File 'lib/rdf/n3/algebra/str/matches.rb', line 15

def resolve(resource, position:)
  resource if resource.literal?
end