rdf 3.1.11 → 3.1.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fb4903dd836362f2ba5883f4af56b2276d879e60c0be2b740fcfd946c2b9bc29
4
- data.tar.gz: e0abcd40f798fa08955649dda90a53f10e775d74d95f4fbbb7680cb8223594a8
3
+ metadata.gz: ff64fa365f10553262446da5494bf2bb592dffe9c409cda37239e0726a5e1f4d
4
+ data.tar.gz: 6915405e0bc437cf0be2a88697145757131ea1d054040b9e7823c26c998a8568
5
5
  SHA512:
6
- metadata.gz: fa91bd5cc0daa34b2055bf0504dd05a67ad433320d316247eee7ecc7e34c4b26a60be3dd944f2b480a3282b6f1175b4af03a740a6697d5a1848e14279093d025
7
- data.tar.gz: b30eea12865c58960d3ee942ff89e6e0cfb1b5bc3d1cc66187356709c389450c03e1d397715c4a807902deacfd10916a1db7c054f03ed289253986b42fefc0e3
6
+ metadata.gz: 0b73a1e41bdb9c53d7dcff97c2b14f785b1f02be8233dcf8ffdd36f9fbc426dcdff5e0af4cb0a31e11fd5edcc76442a2fe6f9d0c1483855a91e340b407ee4753
7
+ data.tar.gz: d93d42dcd04f9ff35676a43d1a71b3e84c5fe1a94118a3b0dd7e94aa708e23e5bb0310fb136fa98956b192f7098eb48fe25a91d22c0287e66041a7f73a704b15
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.1.11
1
+ 3.1.12
@@ -136,8 +136,13 @@ module RDF
136
136
  #
137
137
  # @param [RDF::Statement] statement
138
138
  # @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
141
146
  end
142
147
  alias_method :has_statement?, :statement?
143
148
  alias_method :include?, :statement?
@@ -541,8 +546,12 @@ module RDF
541
546
  # @param [RDF::Resource] value
542
547
  # @return [Boolean]
543
548
  # @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
546
555
  end
547
556
  alias_method :has_term?, :term?
548
557
 
@@ -138,11 +138,22 @@ module RDF
138
138
  end
139
139
 
140
140
  ##
141
- # Returns `true` to indicate that this is a graph.
141
+ # @overload graph?
142
+ # Returns `true` to indicate that this is a graph.
142
143
  #
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
146
157
  end
147
158
 
148
159
  ##
@@ -227,11 +238,15 @@ module RDF
227
238
  # @param [Statement] statement
228
239
  # @return [Boolean]
229
240
  # @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
235
250
  end
236
251
  alias_method :has_statement?, :statement?
237
252
 
@@ -136,23 +136,45 @@ module RDF
136
136
  end
137
137
 
138
138
  ##
139
- # Returns `true` to indicate that this value is a statement.
139
+ # @overload statement?
140
+ # Returns `true` if `self` is a {RDF::Statement}.
140
141
  #
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
144
154
  end
145
155
 
146
156
  ##
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
148
159
  # URI, Node or Literal.
149
160
  #
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
156
178
  end
157
179
 
158
180
  ##
@@ -215,9 +237,22 @@ module RDF
215
237
  end
216
238
 
217
239
  ##
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
221
256
  end
222
257
  alias_method :name?, :graph?
223
258
  alias_method :has_graph?, :graph?
@@ -57,11 +57,21 @@ module RDF
57
57
  end
58
58
 
59
59
  ##
60
- # Returns `true` if `self` is a {RDF::Term}.
60
+ # @overload term?
61
+ # Returns `true` if `self` is a {RDF::Term}.
61
62
  #
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
65
75
  end
66
76
 
67
77
  ##
@@ -29,19 +29,38 @@ module RDF
29
29
  # @see RDF::Statement
30
30
  module Value
31
31
  ##
32
- # Returns `true` if `self` is a {RDF::Graph}.
32
+ # @overload graph?
33
+ # Returns `true` if `self` is a {RDF::Graph}.
33
34
  #
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
37
47
  end
38
48
 
39
49
  ##
40
- # Is this a {RDF::Statement}?
50
+ # @overload statement?
51
+ # Returns `true` if `self` is a {RDF::Statement}.
41
52
  #
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
45
64
  end
46
65
 
47
66
  ##
@@ -53,11 +72,20 @@ module RDF
53
72
  end
54
73
 
55
74
  ##
56
- # Is this a {RDF::Term}?
75
+ # @overload term?
76
+ # Returns `true` if `self` is a {RDF::Term}.
57
77
  #
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
61
89
  end
62
90
 
63
91
  ##
@@ -103,12 +131,21 @@ module RDF
103
131
  end
104
132
 
105
133
  ##
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?
107
136
  #
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]
109
143
  # @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
112
149
  end
113
150
 
114
151
  ##
data/lib/rdf/query.rb CHANGED
@@ -443,11 +443,22 @@ module RDF
443
443
  end
444
444
 
445
445
  ##
446
- # Returns `true` if any pattern contains a variable.
446
+ # @overload variable?
447
+ # Returns `true` if any pattern contains a variable.
447
448
  #
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
451
462
  end
452
463
  alias_method :variables?, :variable?
453
464
  alias_method :has_variables?, :variable?
@@ -114,15 +114,24 @@ class RDF::Query
114
114
  end
115
115
 
116
116
  ##
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
118
123
  # `variables`.
119
124
  #
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]
123
127
  # @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
126
135
  end
127
136
  alias_method :variables?, :variable?
128
137
  alias_method :has_variables?, :variable?
@@ -78,16 +78,25 @@ module RDF; class Query
78
78
  end
79
79
 
80
80
  ##
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
82
87
  # the given `variables`.
83
88
  #
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]
87
91
  # @see RDF::Query::Solution#variable?
88
92
  # @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
91
100
  end
92
101
  alias_method :variables?, :variable?
93
102
  alias_method :have_variables?, :variable?
@@ -87,13 +87,27 @@ class RDF::Query
87
87
  end
88
88
 
89
89
  ##
90
- # Returns `true`.
90
+ # @overload variable?
91
+ # Returns `true` if `self` is a {RDF::Query::Variable}, or does it contain a variable?
91
92
  #
92
- # @return [Boolean]
93
- # @see RDF::Term#variable?
93
+ # @return [Boolean]
94
+ # @overload variable?(variable)
95
+ # Returns `true` if `self` contains the given variable.
96
+ #
97
+ # @param [RDF::Resource] value
98
+ # @return [Boolean]
94
99
  # @since 0.1.7
95
- def variable?
96
- true
100
+ def variable?(*args)
101
+ case args.length
102
+ when 0 then true
103
+ when 1
104
+ case variable = args.first
105
+ when RDF::Query::Variable then self == variable
106
+ when Symbol then to_sym == variable
107
+ else false
108
+ end
109
+ else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
110
+ end
97
111
  end
98
112
 
99
113
  ##
@@ -287,10 +287,22 @@ module RDF
287
287
  end
288
288
 
289
289
  ##
290
- # @private
291
- # @see RDF::Enumerable#graph?
292
- def graph?(graph)
293
- @data.key?(graph)
290
+ # @overload graph?
291
+ # Returns `false` to indicate that this is not a graph.
292
+ #
293
+ # @return [Boolean]
294
+ # @overload graph?(name)
295
+ # Returns `true` if `self` contains the given RDF graph_name.
296
+ #
297
+ # @param [RDF::Resource, false] graph_name
298
+ # Use value `false` to query for the default graph_name
299
+ # @return [Boolean]
300
+ def graph?(*args)
301
+ case args.length
302
+ when 0 then false
303
+ when 1 then @data.key?(args.first)
304
+ else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
305
+ end
294
306
  end
295
307
  alias_method :has_graph?, :graph?
296
308
 
@@ -322,8 +334,12 @@ module RDF
322
334
  # @overload statement?(statement)
323
335
  # @private
324
336
  # @see RDF::Enumerable#statement?
325
- def statement?(statement = nil)
326
- statement && statement_in?(@data, statement)
337
+ def statement?(*args)
338
+ case args.length
339
+ when 0 then false
340
+ when 1 then args.first && statement_in?(@data, args.first)
341
+ else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
342
+ end
327
343
  end
328
344
  alias_method :has_statement?, :statement?
329
345
 
@@ -213,8 +213,12 @@ module RDF
213
213
  # @see RDF::Value#statement?
214
214
  # @overload statement?(statement)
215
215
  # @see RDF::Enumerable#statement?
216
- def statement?(statement = nil)
217
- statement && read_target.has_statement?(statement)
216
+ def statement?(*args)
217
+ case args.length
218
+ when 0 then false
219
+ when 1 then read_target.statement?(*args)
220
+ else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
221
+ end
218
222
  end
219
223
  alias_method :has_statement?, :statement?
220
224
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.11
4
+ version: 3.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arto Bendiken
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-02-15 00:00:00.000000000 Z
13
+ date: 2021-02-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: link_header