Class: RDF::N3::Algebra::Str::Scrape
- Inherits:
-
ListOperator
- Object
- SPARQL::Algebra::Operator::Binary
- ListOperator
- RDF::N3::Algebra::Str::Scrape
- Includes:
- Builtin
- Defined in:
- lib/rdf/n3/algebra/str/scrape.rb
Overview
The subject is a list of two strings. The second string is a regular expression in the perl, python style. It must contain one group (a part in parentheses). If the first string in the list matches the regular expression, then the object is calculated as being the part of the first string which matches the group.
Constant Summary collapse
Instance Attribute Summary
Attributes included from Enumerable
Instance Method Summary collapse
- #resolve(list) ⇒ RDF::Term
-
#validate(list) ⇒ Boolean
Subclasses may override or supplement validate to perform validation on the list subject.
Methods included from Builtin
#each, #evaluate, #hash, #input_operand, #rank, #to_uri
Methods inherited from ListOperator
#as_literal, #execute, #input_operand
Instance Method Details
#resolve(list) ⇒ RDF::Term
15 16 17 18 19 |
# File 'lib/rdf/n3/algebra/str/scrape.rb', line 15 def resolve(list) input, regex = list.to_a md = Regexp.new(regex.to_s).match(input.to_s) RDF::Literal(md[1]) if md end |
#validate(list) ⇒ Boolean
Subclasses may override or supplement validate to perform validation on the list subject
26 27 28 29 30 31 32 33 |
# File 'lib/rdf/n3/algebra/str/scrape.rb', line 26 def validate(list) if super && list.length == 2 true else log_error(NAME) {"list must have exactly two entries: #{list.to_sxp}"} false end end |