Module: RDF::Term

Includes:
Comparable, Value
Included in:
Literal, Query::Variable, Resource
Defined in:
lib/rdf/model/term.rb

Overview

An RDF term.

Terms can be used as subjects, predicates, objects, and graph names of statements.

Since:

  • 0.3.0

Instance Method Summary collapse

Methods included from Value

#anonymous?, #canonicalize, #canonicalize!, #constant?, #graph?, #inspect, #inspect!, #invalid?, #iri?, #list?, #literal?, #node?, #resource?, #start_with?, #statement?, #to_nquads, #to_ntriples, #to_rdf, #type_error, #uri?, #valid?, #validate!, #variable?

Instance Method Details

#<=>(other) ⇒ Integer

This method is abstract.

Compares ‘self` to `other` for sorting purposes.

Subclasses should override this to provide a more meaningful implementation than the default which simply performs a string comparison based on ‘#to_s`.

Parameters:

  • other (Object)

Returns:

  • (Integer)

    ‘-1`, `0`, or `1`

Since:

  • 0.3.0



23
24
25
# File 'lib/rdf/model/term.rb', line 23

def <=>(other)
  self.to_s <=> other.to_s
end

#==(other) ⇒ Integer

This method is abstract.

Compares ‘self` to `other` to implement RDFterm-equal.

Subclasses should override this to provide a more meaningful implementation than the default which simply performs a string comparison based on ‘#to_s`.

Parameters:

  • other (Object)

Returns:

  • (Integer)

    ‘-1`, `0`, or `1`

See Also:

Since:

  • 0.3.0



39
40
41
# File 'lib/rdf/model/term.rb', line 39

def ==(other)
  super
end

#compatible?(other) ⇒ Boolean

Term compatibility according to SPARQL

Returns:

  • (Boolean)

See Also:

Since:

  • 2.0



106
107
108
# File 'lib/rdf/model/term.rb', line 106

def compatible?(other)
  false
end

#eql?(other) ⇒ Integer

This method is abstract.

Determins if ‘self` is the same term as `other`.

Subclasses should override this to provide a more meaningful implementation than the default which simply performs a string comparison based on ‘#to_s`.

Parameters:

  • other (Object)

Returns:

  • (Integer)

    ‘-1`, `0`, or `1`

See Also:

Since:

  • 0.3.0



55
56
57
# File 'lib/rdf/model/term.rb', line 55

def eql?(other)
  super
end

#term?Boolean #term?(name) ⇒ Boolean

Overloads:

  • #term?Boolean

    Returns ‘true` if `self` is a RDF::Term.

    Returns:

    • (Boolean)
  • #term?(name) ⇒ Boolean

    Returns ‘true` if `self` contains the given RDF subject term.

    Parameters:

    Returns:

    • (Boolean)

Since:

  • 0.3.0



69
70
71
72
73
74
75
# File 'lib/rdf/model/term.rb', line 69

def term?(*args)
  case args.length
  when 0 then true
  when 1 then false
  else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
  end
end

#termsArray<RDF::Value>

Returns an array including just itself.

Returns:

Since:

  • 0.3.0



89
90
91
# File 'lib/rdf/model/term.rb', line 89

def terms
  [self]
end

#to_baseSring

Returns the base representation of this term.

Returns:

  • (Sring)

Since:

  • 0.3.0



97
98
99
# File 'lib/rdf/model/term.rb', line 97

def to_base
  RDF::NTriples.serialize(self).freeze
end

#to_termRDF::Value

Returns itself.

Returns:

Since:

  • 0.3.0



81
82
83
# File 'lib/rdf/model/term.rb', line 81

def to_term
  self
end