Class: RDF::N3::Algebra::Str::Scrape

Inherits:
ListOperator
  • Object
show all
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.

Examples:

("abcdef" "ab(..)ef") string:scrape "cd"

Constant Summary collapse

NAME =
:strScrape
URI =
RDF::N3::Str.scrape

Instance Attribute Summary

Attributes included from Enumerable

#existentials, #universals

Instance Method Summary collapse

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

Parameters:

Returns:

See Also:

  • ListOperator#evaluate


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

Parameters:

Returns:

  • (Boolean)


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