module RDF::Value
An RDF
value.
This is the basis for the RDF.rb class hierarchy. Anything that can be a term of {RDF::Statement RDF
statements} should directly or indirectly include this module, but it does not define classes that can be included within a {RDF::Statement}, for this see {RDF::Term}.
@example Checking if a value is a resource (blank node or URI
reference)
value.resource?
@example Checking if a value is a blank node
value.node?
@example Checking if a value is a URI
reference
value.uri? value.iri?
@example Checking if a value is a literal
value.literal?
@see RDF::Literal
@see RDF::Node
@see RDF::Resource
@see RDF::URI
@see RDF::Graph
@see RDF::List
@see RDF::Statement
Extensions for ‘RDF::Value`.
Extensions for ‘RDF::Value`.
Public Instance Methods
Is this value named?
@return [Boolean] ‘true` or `false`
# File lib/rdf/model/value.rb, line 166 def anonymous? false end
Returns a copy of this value converted into its canonical representation.
@return [RDF::Value] @since 1.0.8
# File lib/rdf/model/value.rb, line 223 def canonicalize self.dup.canonicalize! end
Converts this value into its canonical representation.
Should be overridden by concrete classes.
@return [RDF::Value] ‘self` @since 1.0.8
# File lib/rdf/model/value.rb, line 234 def canonicalize! self end
Is this constant, or are all of its components constant?
Same as ‘!variable?`
@return [Boolean] ‘true` or `false` @see variable?
# File lib/rdf/model/value.rb, line 158 def constant? !(variable?) end
@overload graph?
Returns `true` if `self` is a {RDF::Graph}. @return [Boolean]
@overload graph?(name)
Returns `true` if `self` contains the given RDF graph_name. @param [RDF::Resource, false] graph_name Use value `false` to query for the default graph_name @return [Boolean]
# 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
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`.
@return [String]
# File lib/rdf/model/value.rb, line 261 def inspect sprintf("#<%s:%#0x(%s)>", self.class.name, __id__, to_s) end
Outputs a developer-friendly representation of ‘self` to `stderr`.
@return [void]
# File lib/rdf/model/value.rb, line 269 def inspect! warn(inspect) end
Is this value invalid, or is it composed of any invalid components?
@return [Boolean] ‘true` or `false` @since 0.2.1
# File lib/rdf/model/value.rb, line 184 def invalid? !valid? end
Is this an {RDF::IRI}?
By default this is simply an alias for {RDF::Value#uri?}.
@return [Boolean]
# File lib/rdf/model/value.rb, line 121 def iri? uri? end
Is this a {RDF::List}?
@return [Boolean]
# File lib/rdf/model/value.rb, line 70 def list? false end
Is this a {RDF::Literal}?
@return [Boolean]
# File lib/rdf/model/value.rb, line 103 def literal? false end
Is this a {RDF::Node}, or does it contain a node?
@return [Boolean]
# File lib/rdf/model/value.rb, line 111 def node? false end
Is this a {RDF::Resource}?
@return [Boolean]
# File lib/rdf/model/value.rb, line 95 def resource? false end
Returns ‘true` if this Value
starts with any of the given strings.
@example
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
@param [Array<#to_s>] *args Any number of strings to check against. @return [Boolean] ‘true` or `false` @see String#start_with? @since 0.3.0
# File lib/rdf/model/value.rb, line 212 def start_with?(*args) to_s.start_with?(*args.map(&:to_s)) end
@overload statement?
Returns `true` if `self` is a {RDF::Statement}. @return [Boolean]
@overload statement?(statement)
Returns `true` if `self` contains the given {RDF::Statement}. @param [RDF::Statement] statement @return [Boolean]
# 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
@overload term?
Returns `true` if `self` is a {RDF::Term}. @return [Boolean]
@overload term?(name)
Returns `true` if `self` contains the given RDF subject term. @param [RDF::Resource] value @return [Boolean]
# 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
Returns the N-Quads representation of this value.
This method is only available when the ‘rdf/nquads’ serializer has been explicitly required.
@return [String] @since 0.4.0
# File lib/rdf/nquads.rb, line 168 def to_nquads RDF::NQuads.serialize(self) end
Returns the N-Triples representation of this value.
This method is only available when the ‘rdf/ntriples’ serializer has been explicitly required.
@return [String] @since 0.2.1
# File lib/rdf/ntriples.rb, line 104 def to_ntriples RDF::NTriples.serialize(self) end
Returns an ‘RDF::Value` representation of `self`.
@return [RDF::Value]
# File lib/rdf/model/value.rb, line 242 def to_rdf self end
Returns an ‘RDF::Term` representation of `self`.
@return [RDF::Value]
# File lib/rdf/model/value.rb, line 250 def to_term raise NotImplementedError, "#{self.class}#read_triple" # override in subclasses end
Default implementation of ‘type_error`, which returns false. Classes including RDF::TypeCheck
will raise TypeError instead.
@return [false]
# File lib/rdf/model/value.rb, line 279 def type_error(message) false end
Is this an {RDF::URI}?
@return [Boolean]
# File lib/rdf/model/value.rb, line 129 def uri? false end
Is this value valid, and composed only of valid components?
@return [Boolean] ‘true` or `false` @since 0.3.9
# File lib/rdf/model/value.rb, line 175 def valid? true end
Default validate! implementation, overridden in concrete classes @return [RDF::Value] ‘self` @raise [ArgumentError] if the value is invalid @since 0.3.9
# File lib/rdf/model/value.rb, line 193 def validate! raise ArgumentError, "#{self.inspect} is not valid" if invalid? self end
@overload variable?
Returns `true` if `self` is a {RDF::Query::Variable}, or does it contain a variable? @return [Boolean]
@overload variable?(variable)
Returns `true` if `self` contains the given variable. @param [RDF::Resource] value @return [Boolean]
@since 0.1.7
# 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