Module: RDF::Value

Included in:
Graph, List, Term
Defined in:
lib/rdf/nquads.rb,
lib/rdf/ntriples.rb,
lib/rdf/model/value.rb

Overview

An RDF value.

This is the basis for the RDF.rb class hierarchy. Anything that can be a term of RDF statements should directly or indirectly include this module, but it does not define classes that can be included within a Statement, for this see Term.

Examples:

Checking if a value is a resource (blank node or URI reference)

value.resource?

Checking if a value is a blank node

value.node?

Checking if a value is a URI reference

value.uri?
value.iri?

Checking if a value is a literal

value.literal?

See Also:

Instance Method Summary collapse

Instance Method Details

#anonymous?Boolean

Is this value named?

Returns:

  • (Boolean)

    true or false



166
167
168
# File 'lib/rdf/model/value.rb', line 166

def anonymous?
  false
end

#canonicalizeRDF::Value

Returns a copy of this value converted into its canonical representation.

Returns:

Since:

  • 1.0.8



223
224
225
# File 'lib/rdf/model/value.rb', line 223

def canonicalize
  self.dup.canonicalize!
end

#canonicalize!RDF::Value

Converts this value into its canonical representation.

Should be overridden by concrete classes.

Returns:

Since:

  • 1.0.8



234
235
236
# File 'lib/rdf/model/value.rb', line 234

def canonicalize!
  self
end

#constant?Boolean

Is this constant, or are all of its components constant?

Same as !variable?

Returns:

  • (Boolean)

    true or false

See Also:



158
159
160
# File 'lib/rdf/model/value.rb', line 158

def constant?
  !(variable?)
end

#graph?Boolean #graph?(name) ⇒ Boolean

Overloads:

  • #graph?Boolean

    Returns true if self is a Graph.

    Returns:

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

    Returns true if self contains the given RDF graph_name.

    Parameters:

    • graph_name (RDF::Resource, false)

      Use value false to query for the default graph_name

    Returns:

    • (Boolean)


42
43
44
45
46
47
# File 'lib/rdf/model/value.rb', line 42

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

#inspectString

Returns a developer-friendly representation of self.

The result will be of the format #<RDF::Value::0x12345678(...)>, where ... is the string returned by #to_s.

Returns:

  • (String)


261
262
263
# File 'lib/rdf/model/value.rb', line 261

def inspect
  sprintf("#<%s:%#0x(%s)>", self.class.name, __id__, to_s)
end

#inspect!

This method returns an undefined value.

Outputs a developer-friendly representation of self to stderr.



269
270
271
# File 'lib/rdf/model/value.rb', line 269

def inspect!
  warn(inspect)
end

#invalid?Boolean

Is this value invalid, or is it composed of any invalid components?

Returns:

  • (Boolean)

    true or false

Since:

  • 0.2.1



184
185
186
# File 'lib/rdf/model/value.rb', line 184

def invalid?
  !valid?
end

#iri?Boolean

Is this an IRI?

By default this is simply an alias for #uri?.

Returns:

  • (Boolean)


121
122
123
# File 'lib/rdf/model/value.rb', line 121

def iri?
  uri?
end

#list?Boolean

Is this a List?

Returns:

  • (Boolean)


70
71
72
# File 'lib/rdf/model/value.rb', line 70

def list?
  false
end

#literal?Boolean

Is this a Literal?

Returns:

  • (Boolean)


103
104
105
# File 'lib/rdf/model/value.rb', line 103

def literal?
  false
end

#node?Boolean

Is this a Node, or does it contain a node?

Returns:

  • (Boolean)


111
112
113
# File 'lib/rdf/model/value.rb', line 111

def node?
  false
end

#resource?Boolean

Is this a Resource?

Returns:

  • (Boolean)


95
96
97
# File 'lib/rdf/model/value.rb', line 95

def resource?
  false
end

#start_with?(*args) ⇒ Boolean Also known as: starts_with?

Returns true if this Value starts with any of the given strings.

Examples:

RDF::URI('http://example.org/').start_with?('http')     #=> true
RDF::Node('_:foo').start_with?('_:bar')                 #=> false
RDF::Litera('Apple').start_with?('Orange')              #=> false
RDF::Litera('Apple').start_with?('Orange', 'Apple')     #=> true

Parameters:

  • *args (Array<#to_s>)

    Any number of strings to check against.

Returns:

  • (Boolean)

    true or false

See Also:

  • String#start_with?

Since:

  • 0.3.0



212
213
214
# File 'lib/rdf/model/value.rb', line 212

def start_with?(*args)
  to_s.start_with?(*args.map(&:to_s))
end

#statement?Boolean #statement?(statement) ⇒ Boolean

Overloads:

  • #statement?Boolean

    Returns true if self is a Statement.

    Returns:

    • (Boolean)
  • #statement?(statement) ⇒ Boolean

    Returns true if self contains the given Statement.

    Parameters:

    Returns:

    • (Boolean)


59
60
61
62
63
64
# File 'lib/rdf/model/value.rb', line 59

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

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

Overloads:

  • #term?Boolean

    Returns true if self is a Term.

    Returns:

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

    Returns true if self contains the given RDF subject term.

    Parameters:

    Returns:

    • (Boolean)


84
85
86
87
88
89
# File 'lib/rdf/model/value.rb', line 84

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

#to_nquadsString

Returns the N-Quads representation of this value.

This method is only available when the ‘rdf/nquads’ serializer has been explicitly required.

Returns:

  • (String)

Since:

  • 0.4.0



169
170
171
# File 'lib/rdf/nquads.rb', line 169

def to_nquads
  RDF::NQuads.serialize(self)
end

#to_ntriplesString

Returns the N-Triples representation of this value.

This method is only available when the ‘rdf/ntriples’ serializer has been explicitly required.

Returns:

  • (String)

Since:

  • 0.2.1



104
105
106
# File 'lib/rdf/ntriples.rb', line 104

def to_ntriples
  RDF::NTriples.serialize(self)
end

#to_rdfRDF::Value

Returns an RDF::Value representation of self.

Returns:



242
243
244
# File 'lib/rdf/model/value.rb', line 242

def to_rdf
  self
end

#to_termRDF::Value

Returns an RDF::Term representation of self.

Returns:

Raises:

  • (NotImplementedError)


250
251
252
# File 'lib/rdf/model/value.rb', line 250

def to_term
  raise NotImplementedError, "#{self.class}#read_triple" # override in subclasses
end

#type_error(message) ⇒ false

Default implementation of type_error, which returns false. Classes including RDF::TypeCheck will raise TypeError instead.

Returns:

  • (false)


279
280
281
# File 'lib/rdf/model/value.rb', line 279

def type_error(message)
  false
end

#uri?Boolean

Is this an URI?

Returns:

  • (Boolean)


129
130
131
# File 'lib/rdf/model/value.rb', line 129

def uri?
  false
end

#valid?Boolean

Is this value valid, and composed only of valid components?

Returns:

  • (Boolean)

    true or false

Since:

  • 0.3.9



175
176
177
# File 'lib/rdf/model/value.rb', line 175

def valid?
  true
end

#validate!RDF::Value Also known as: validate

Default validate! implementation, overridden in concrete classes

Returns:

Raises:

  • (ArgumentError)

    if the value is invalid

Since:

  • 0.3.9



193
194
195
196
# File 'lib/rdf/model/value.rb', line 193

def validate!
  raise ArgumentError, "#{self.inspect} is not valid" if invalid?
  self
end

#variable?Boolean #variable?(variable) ⇒ Boolean

Overloads:

  • #variable?Boolean

    Returns true if self is a Query::Variable, or does it contain a variable?

    Returns:

    • (Boolean)
  • #variable?(variable) ⇒ Boolean

    Returns true if self contains the given variable.

    Parameters:

    Returns:

    • (Boolean)

Since:

  • 0.1.7



144
145
146
147
148
149
# File 'lib/rdf/model/value.rb', line 144

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