lib/rdf/model/statement.rb in rdf-3.1.11 vs lib/rdf/model/statement.rb in rdf-3.1.12
- old
+ new
@@ -134,27 +134,49 @@
raise ArgumentError, "expected graph_name to be nil or a resource, was #{@graph_name.inspect}"
end
end
##
- # Returns `true` to indicate that this value is a statement.
+ # @overload statement?
+ # Returns `true` if `self` is a {RDF::Statement}.
#
- # @return [Boolean]
- def statement?
- true
+ # @return [Boolean]
+ # @overload statement?(statement)
+ # Returns `true` if `self` contains the given {RDF::Statement}.
+ #
+ # @param [RDF::Statement] statement
+ # @return [Boolean]
+ def statement?(*args)
+ case args.length
+ when 0 then true
+ when 1 then self == args.first || subject.statement?(*args) || object.statement?(*args)
+ else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
+ end
end
##
- # Returns `true` if any element of the statement is not a
+ # @overload variable?
+ # Returns `true` if any element of the statement is not a
# URI, Node or Literal.
#
- # @return [Boolean]
- def variable?
- !(subject? && subject.constant? &&
- predicate? && predicate.constant? &&
- object? && object.constant? &&
- (graph? ? graph_name.constant? : true))
+ # @return [Boolean]
+ # @overload variable?(variables)
+ # Returns `true` if this statement contains any of the variables.
+ #
+ # @param [Array<Symbol, #to_sym>] variables
+ # @return [Boolean]
+ def variable?(*args)
+ case args.length
+ when 0
+ !(subject? && subject.constant? &&
+ predicate? && predicate.constant? &&
+ object? && object.constant? &&
+ (graph? ? graph_name.constant? : true))
+ when 1
+ to_quad.any? {|t| t.respond_to?(:variable?) && t.variable?(*args)}
+ else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
+ end
end
##
# Returns `true` if any element of the statement is, itself, a statement.
#
@@ -213,12 +235,25 @@
def complete?
!incomplete?
end
##
- # @return [Boolean]
- def graph?
- !!graph_name
+ # @overload graph?
+ # Returns `true` if the statement has a graph name.
+ #
+ # @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]
+ def graph?(*args)
+ case args.length
+ when 0 then !!graph_name
+ when 1 then graph_name == args.first
+ else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
+ end
end
alias_method :name?, :graph?
alias_method :has_graph?, :graph?
alias_method :has_name?, :graph?