@@ -136,23 +136,45 @@ def initialize!
136136 end
137137
138138 ##
139- # Returns `true` to indicate that this value is a statement.
139+ # @overload statement?
140+ # Returns `true` if `self` is a {RDF::Statement}.
140141 #
141- # @return [Boolean]
142- def statement?
143- true
142+ # @return [Boolean]
143+ # @overload statement?(statement)
144+ # Returns `true` if `self` contains the given {RDF::Statement}.
145+ #
146+ # @param [RDF::Statement] statement
147+ # @return [Boolean]
148+ def statement? ( *args )
149+ case args . length
150+ when 0 then true
151+ when 1 then self == args . first || subject . statement? ( *args ) || object . statement? ( *args )
152+ else raise ArgumentError ( "wrong number of arguments (given #{ args . length } , expected 0 or 1)" )
153+ end
144154 end
145155
146156 ##
147- # Returns `true` if any element of the statement is not a
157+ # @overload variable?
158+ # Returns `true` if any element of the statement is not a
148159 # URI, Node or Literal.
149160 #
150- # @return [Boolean]
151- def variable?
152- !( subject? && subject . constant? &&
153- predicate? && predicate . constant? &&
154- object? && object . constant? &&
155- ( graph? ? graph_name . constant? : true ) )
161+ # @return [Boolean]
162+ # @overload variable?(variables)
163+ # Returns `true` if this statement contains any of the variables.
164+ #
165+ # @param [Array<Symbol, #to_sym>] variables
166+ # @return [Boolean]
167+ def variable? ( *args )
168+ case args . length
169+ when 0
170+ !( subject? && subject . constant? &&
171+ predicate? && predicate . constant? &&
172+ object? && object . constant? &&
173+ ( graph? ? graph_name . constant? : true ) )
174+ when 1
175+ to_quad . any? { |t | t . respond_to? ( :variable? ) && t . variable? ( *args ) }
176+ else raise ArgumentError ( "wrong number of arguments (given #{ args . length } , expected 0 or 1)" )
177+ end
156178 end
157179
158180 ##
@@ -215,9 +237,22 @@ def complete?
215237 end
216238
217239 ##
218- # @return [Boolean]
219- def graph?
220- !!graph_name
240+ # @overload graph?
241+ # Returns `true` if the statement has a graph name.
242+ #
243+ # @return [Boolean]
244+ # @overload graph?(name)
245+ # Returns `true` if `self` contains the given RDF graph_name.
246+ #
247+ # @param [RDF::Resource, false] graph_name
248+ # Use value `false` to query for the default graph_name
249+ # @return [Boolean]
250+ def graph? ( *args )
251+ case args . length
252+ when 0 then !!graph_name
253+ when 1 then graph_name == args . first
254+ else raise ArgumentError ( "wrong number of arguments (given #{ args . length } , expected 0 or 1)" )
255+ end
221256 end
222257 alias_method :name? , :graph?
223258 alias_method :has_graph? , :graph?
0 commit comments