Skip to content

Commit

Permalink
Finish 3.1.12
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Feb 16, 2021
2 parents 08c07c0 + 878d42c commit 73fcc5a
Show file tree
Hide file tree
Showing 14 changed files with 251 additions and 77 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.11
3.1.12
17 changes: 13 additions & 4 deletions lib/rdf/mixin/enumerable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,13 @@ def statements(**options)
#
# @param [RDF::Statement] statement
# @return [Boolean]
def statement?(statement = nil)
statement && !enum_statement.find { |s| s.eql?(statement) }.nil?
def statement?(*args)
case args.length
when 0 then false
when 1
args.first && !enum_statement.find { |s| s.eql?(args.first) }.nil?
else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
end
end
alias_method :has_statement?, :statement?
alias_method :include?, :statement?
Expand Down Expand Up @@ -541,8 +546,12 @@ def terms(unique: true)
# @param [RDF::Resource] value
# @return [Boolean]
# @since 2.0
def term?(value = nil)
value && enum_term.include?(value)
def term?(*args)
case args.length
when 0 then super
when 1 then args.first && enum_term.include?(args.first)
else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
end
end
alias_method :has_term?, :term?

Expand Down
33 changes: 24 additions & 9 deletions lib/rdf/model/graph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,22 @@ def load!(*args)
end

##
# Returns `true` to indicate that this is a graph.
# @overload graph?
# Returns `true` to indicate that this is a graph.
#
# @return [Boolean]
def graph?
true
# @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 true
when 1 then graph_name == args.first
else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
end
end

##
Expand Down Expand Up @@ -227,11 +238,15 @@ def count
# @param [Statement] statement
# @return [Boolean]
# @see RDF::Enumerable#statement?
def statement?(statement = nil)
return false if statement.nil?
statement = statement.dup
statement.graph_name = graph_name
@data.statement?(statement)
def statement?(*args)
case args.length
when 0 then false
when 1
statement = args.first.dup
statement.graph_name = graph_name
@data.statement?(statement)
else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
end
end
alias_method :has_statement?, :statement?

Expand Down
63 changes: 49 additions & 14 deletions lib/rdf/model/statement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,23 +136,45 @@ def initialize!
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

##
Expand Down Expand Up @@ -215,9 +237,22 @@ def complete?
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?
Expand Down
18 changes: 14 additions & 4 deletions lib/rdf/model/term.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,21 @@ def eql?(other)
end

##
# Returns `true` if `self` is a {RDF::Term}.
# @overload term?
# Returns `true` if `self` is a {RDF::Term}.
#
# @return [Boolean]
def term?
true
# @return [Boolean]
# @overload term?(name)
# Returns `true` if `self` contains the given RDF subject term.
#
# @param [RDF::Resource] value
# @return [Boolean]
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

##
Expand Down
69 changes: 53 additions & 16 deletions lib/rdf/model/value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,38 @@ module RDF
# @see RDF::Statement
module Value
##
# Returns `true` if `self` is a {RDF::Graph}.
# @overload graph?
# Returns `true` if `self` is a {RDF::Graph}.
#
# @return [Boolean]
def graph?
false
# @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, 1 then false
else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
end
end

##
# Is this a {RDF::Statement}?
# @overload statement?
# Returns `true` if `self` is a {RDF::Statement}.
#
# @return [Boolean]
def statement?
false
# @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, 1 then false
else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
end
end

##
Expand All @@ -53,11 +72,20 @@ def list?
end

##
# Is this a {RDF::Term}?
# @overload term?
# Returns `true` if `self` is a {RDF::Term}.
#
# @return [Boolean]
def term?
false
# @return [Boolean]
# @overload term?(name)
# Returns `true` if `self` contains the given RDF subject term.
#
# @param [RDF::Resource] value
# @return [Boolean]
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

##
Expand Down Expand Up @@ -103,12 +131,21 @@ def uri?
end

##
# Is this a {RDF::Query::Variable}, or does it contain a variable?
# @overload variable?
# Returns `true` if `self` is a {RDF::Query::Variable}, or does it contain a variable?
#
# @return [Boolean]
# @return [Boolean]
# @overload variable?(variable)
# Returns `true` if `self` contains the given variable.
#
# @param [RDF::Resource] value
# @return [Boolean]
# @since 0.1.7
def variable?
false
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

##
Expand Down
19 changes: 15 additions & 4 deletions lib/rdf/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -443,11 +443,22 @@ def apply_graph_name(graph_name = nil)
end

##
# Returns `true` if any pattern contains a variable.
# @overload variable?
# Returns `true` if any pattern contains a variable.
#
# @return [Boolean]
def variable?
!variables.empty?
# @return [Boolean]
# @overload variable?(variables)
# Returns `true` if any pattern contains any of the variables.
#
# @param [Array<Symbol, #to_sym>] variables
# @return [Boolean]
def variable?(*args)
case args.length
when 0 then !variables.empty?
when 1
patterns.any? {|p| p.variable?(*args)}
else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
end
end
alias_method :variables?, :variable?
alias_method :has_variables?, :variable?
Expand Down
21 changes: 15 additions & 6 deletions lib/rdf/query/solution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,24 @@ def enum_value
end

##
# Returns `true` if this solution contains bindings for any of the given
# @overload variable?
# Returns `false`.
#
# @return [Boolean]
# @overload variable?(variables)
# Returns `true` if this solution contains bindings for any of the given
# `variables`.
#
# @param [Array<Symbol, #to_sym>] variables
# an array of variables to check
# @return [Boolean] `true` or `false`
# @param [Array<Symbol, #to_sym>] variables
# @return [Boolean]
# @since 0.3.0
def variable?(variables)
variables.any? { |variable| bound?(variable) }
def variable?(*args)
case args.length
when 0 then false
when 1
args.first.any? { |variable| bound?(variable) }
else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
end
end
alias_method :variables?, :variable?
alias_method :has_variables?, :variable?
Expand Down
21 changes: 15 additions & 6 deletions lib/rdf/query/solutions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,25 @@ def variable_names
end

##
# Returns `true` if this solution sequence contains bindings for any of
# @overload variable?
# Returns `false`.
#
# @return [Boolean]
# @overload variable?(variables)
# Returns `true` if this solution sequence contains bindings for any of
# the given `variables`.
#
# @param [Array<Symbol, #to_sym>] variables
# an array of variables to check
# @return [Boolean] `true` or `false`
# @param [Array<Symbol, #to_sym>] variables
# @return [Boolean]
# @see RDF::Query::Solution#variable?
# @see RDF::Query#execute
def variable?(variables)
self.any? { |solution| solution.variables?(variables) }
def variable?(*args)
case args.length
when 0 then false
when 1
self.any? { |solution| solution.variables?(args.first) }
else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
end
end
alias_method :variables?, :variable?
alias_method :have_variables?, :variable?
Expand Down
Loading

0 comments on commit 73fcc5a

Please sign in to comment.