Skip to content

Commit 73fcc5a

Browse files
committed
Finish 3.1.12
2 parents 08c07c0 + 878d42c commit 73fcc5a

File tree

14 files changed

+251
-77
lines changed

14 files changed

+251
-77
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.1.11
1+
3.1.12

lib/rdf/mixin/enumerable.rb

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,13 @@ def statements(**options)
136136
#
137137
# @param [RDF::Statement] statement
138138
# @return [Boolean]
139-
def statement?(statement = nil)
140-
statement && !enum_statement.find { |s| s.eql?(statement) }.nil?
139+
def statement?(*args)
140+
case args.length
141+
when 0 then false
142+
when 1
143+
args.first && !enum_statement.find { |s| s.eql?(args.first) }.nil?
144+
else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
145+
end
141146
end
142147
alias_method :has_statement?, :statement?
143148
alias_method :include?, :statement?
@@ -541,8 +546,12 @@ def terms(unique: true)
541546
# @param [RDF::Resource] value
542547
# @return [Boolean]
543548
# @since 2.0
544-
def term?(value = nil)
545-
value && enum_term.include?(value)
549+
def term?(*args)
550+
case args.length
551+
when 0 then super
552+
when 1 then args.first && enum_term.include?(args.first)
553+
else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
554+
end
546555
end
547556
alias_method :has_term?, :term?
548557

lib/rdf/model/graph.rb

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,22 @@ def load!(*args)
138138
end
139139

140140
##
141-
# Returns `true` to indicate that this is a graph.
141+
# @overload graph?
142+
# Returns `true` to indicate that this is a graph.
142143
#
143-
# @return [Boolean]
144-
def graph?
145-
true
144+
# @return [Boolean]
145+
# @overload graph?(name)
146+
# Returns `true` if `self` contains the given RDF graph_name.
147+
#
148+
# @param [RDF::Resource, false] graph_name
149+
# Use value `false` to query for the default graph_name
150+
# @return [Boolean]
151+
def graph?(*args)
152+
case args.length
153+
when 0 then true
154+
when 1 then graph_name == args.first
155+
else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
156+
end
146157
end
147158

148159
##
@@ -227,11 +238,15 @@ def count
227238
# @param [Statement] statement
228239
# @return [Boolean]
229240
# @see RDF::Enumerable#statement?
230-
def statement?(statement = nil)
231-
return false if statement.nil?
232-
statement = statement.dup
233-
statement.graph_name = graph_name
234-
@data.statement?(statement)
241+
def statement?(*args)
242+
case args.length
243+
when 0 then false
244+
when 1
245+
statement = args.first.dup
246+
statement.graph_name = graph_name
247+
@data.statement?(statement)
248+
else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
249+
end
235250
end
236251
alias_method :has_statement?, :statement?
237252

lib/rdf/model/statement.rb

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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?

lib/rdf/model/term.rb

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,21 @@ def eql?(other)
5757
end
5858

5959
##
60-
# Returns `true` if `self` is a {RDF::Term}.
60+
# @overload term?
61+
# Returns `true` if `self` is a {RDF::Term}.
6162
#
62-
# @return [Boolean]
63-
def term?
64-
true
63+
# @return [Boolean]
64+
# @overload term?(name)
65+
# Returns `true` if `self` contains the given RDF subject term.
66+
#
67+
# @param [RDF::Resource] value
68+
# @return [Boolean]
69+
def term?(*args)
70+
case args.length
71+
when 0 then true
72+
when 1 then false
73+
else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
74+
end
6575
end
6676

6777
##

lib/rdf/model/value.rb

Lines changed: 53 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,38 @@ module RDF
2929
# @see RDF::Statement
3030
module Value
3131
##
32-
# Returns `true` if `self` is a {RDF::Graph}.
32+
# @overload graph?
33+
# Returns `true` if `self` is a {RDF::Graph}.
3334
#
34-
# @return [Boolean]
35-
def graph?
36-
false
35+
# @return [Boolean]
36+
# @overload graph?(name)
37+
# Returns `true` if `self` contains the given RDF graph_name.
38+
#
39+
# @param [RDF::Resource, false] graph_name
40+
# Use value `false` to query for the default graph_name
41+
# @return [Boolean]
42+
def graph?(*args)
43+
case args.length
44+
when 0, 1 then false
45+
else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
46+
end
3747
end
3848

3949
##
40-
# Is this a {RDF::Statement}?
50+
# @overload statement?
51+
# Returns `true` if `self` is a {RDF::Statement}.
4152
#
42-
# @return [Boolean]
43-
def statement?
44-
false
53+
# @return [Boolean]
54+
# @overload statement?(statement)
55+
# Returns `true` if `self` contains the given {RDF::Statement}.
56+
#
57+
# @param [RDF::Statement] statement
58+
# @return [Boolean]
59+
def statement?(*args)
60+
case args.length
61+
when 0, 1 then false
62+
else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
63+
end
4564
end
4665

4766
##
@@ -53,11 +72,20 @@ def list?
5372
end
5473

5574
##
56-
# Is this a {RDF::Term}?
75+
# @overload term?
76+
# Returns `true` if `self` is a {RDF::Term}.
5777
#
58-
# @return [Boolean]
59-
def term?
60-
false
78+
# @return [Boolean]
79+
# @overload term?(name)
80+
# Returns `true` if `self` contains the given RDF subject term.
81+
#
82+
# @param [RDF::Resource] value
83+
# @return [Boolean]
84+
def term?(*args)
85+
case args.length
86+
when 0, 1 then false
87+
else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
88+
end
6189
end
6290

6391
##
@@ -103,12 +131,21 @@ def uri?
103131
end
104132

105133
##
106-
# Is this a {RDF::Query::Variable}, or does it contain a variable?
134+
# @overload variable?
135+
# Returns `true` if `self` is a {RDF::Query::Variable}, or does it contain a variable?
107136
#
108-
# @return [Boolean]
137+
# @return [Boolean]
138+
# @overload variable?(variable)
139+
# Returns `true` if `self` contains the given variable.
140+
#
141+
# @param [RDF::Resource] value
142+
# @return [Boolean]
109143
# @since 0.1.7
110-
def variable?
111-
false
144+
def variable?(*args)
145+
case args.length
146+
when 0, 1 then false
147+
else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
148+
end
112149
end
113150

114151
##

lib/rdf/query.rb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,11 +443,22 @@ def apply_graph_name(graph_name = nil)
443443
end
444444

445445
##
446-
# Returns `true` if any pattern contains a variable.
446+
# @overload variable?
447+
# Returns `true` if any pattern contains a variable.
447448
#
448-
# @return [Boolean]
449-
def variable?
450-
!variables.empty?
449+
# @return [Boolean]
450+
# @overload variable?(variables)
451+
# Returns `true` if any pattern contains any of the variables.
452+
#
453+
# @param [Array<Symbol, #to_sym>] variables
454+
# @return [Boolean]
455+
def variable?(*args)
456+
case args.length
457+
when 0 then !variables.empty?
458+
when 1
459+
patterns.any? {|p| p.variable?(*args)}
460+
else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
461+
end
451462
end
452463
alias_method :variables?, :variable?
453464
alias_method :has_variables?, :variable?

lib/rdf/query/solution.rb

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,24 @@ def enum_value
114114
end
115115

116116
##
117-
# Returns `true` if this solution contains bindings for any of the given
117+
# @overload variable?
118+
# Returns `false`.
119+
#
120+
# @return [Boolean]
121+
# @overload variable?(variables)
122+
# Returns `true` if this solution contains bindings for any of the given
118123
# `variables`.
119124
#
120-
# @param [Array<Symbol, #to_sym>] variables
121-
# an array of variables to check
122-
# @return [Boolean] `true` or `false`
125+
# @param [Array<Symbol, #to_sym>] variables
126+
# @return [Boolean]
123127
# @since 0.3.0
124-
def variable?(variables)
125-
variables.any? { |variable| bound?(variable) }
128+
def variable?(*args)
129+
case args.length
130+
when 0 then false
131+
when 1
132+
args.first.any? { |variable| bound?(variable) }
133+
else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
134+
end
126135
end
127136
alias_method :variables?, :variable?
128137
alias_method :has_variables?, :variable?

lib/rdf/query/solutions.rb

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,25 @@ def variable_names
7878
end
7979

8080
##
81-
# Returns `true` if this solution sequence contains bindings for any of
81+
# @overload variable?
82+
# Returns `false`.
83+
#
84+
# @return [Boolean]
85+
# @overload variable?(variables)
86+
# Returns `true` if this solution sequence contains bindings for any of
8287
# the given `variables`.
8388
#
84-
# @param [Array<Symbol, #to_sym>] variables
85-
# an array of variables to check
86-
# @return [Boolean] `true` or `false`
89+
# @param [Array<Symbol, #to_sym>] variables
90+
# @return [Boolean]
8791
# @see RDF::Query::Solution#variable?
8892
# @see RDF::Query#execute
89-
def variable?(variables)
90-
self.any? { |solution| solution.variables?(variables) }
93+
def variable?(*args)
94+
case args.length
95+
when 0 then false
96+
when 1
97+
self.any? { |solution| solution.variables?(args.first) }
98+
else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
99+
end
91100
end
92101
alias_method :variables?, :variable?
93102
alias_method :have_variables?, :variable?

0 commit comments

Comments
 (0)