Skip to content

Commit 84063a9

Browse files
committed
Finish 3.2.6
2 parents 13bc125 + 6f9e254 commit 84063a9

File tree

6 files changed

+79
-8
lines changed

6 files changed

+79
-8
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.2.5
1+
3.2.6

lib/rdf/model/literal/temporal.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def milliseconds?
128128
#
129129
# @return [String]
130130
def to_s
131-
@string || (@object.strftime(self.class.const_get(:FORMAT)).sub('.000', '') + self.tz)
131+
@string ||= (@object.strftime(self.class.const_get(:FORMAT)).sub('.000', '') + self.tz)
132132
end
133133

134134
##
@@ -146,18 +146,18 @@ def to_s
146146
#
147147
# Otherwise, the timezone is set based on the difference between the current timezone offset (if any) and `zone`.
148148
#
149-
# @param [String] zone (nil) In the form of {ZONE_GRAMMAR}.
149+
# @param [DayTimeDuration, String] zone (nil) In the form of {ZONE_GRAMMAR}.
150150
# @return [Temporal] `self`
151151
# @raise [RangeError] if `zone < -14*60` or `zone > 14*60`
152152
# @see https://www.w3.org/TR/xpath-functions/#func-adjust-dateTime-to-timezone
153153
def adjust_to_timezone!(*args)
154154
zone = args.empty? ? '+00:00' : args.first
155-
if zone.nil?
155+
if zone.to_s.empty?
156156
# Remove timezone component
157157
@object = self.class.new(@object.strftime(self.class.const_get(:FORMAT))).object
158158
@zone = nil
159159
else
160-
md = zone.match(ZONE_GRAMMAR)
160+
md = zone.to_s.match(ZONE_GRAMMAR)
161161
raise ArgumentError,
162162
"expected #{zone.inspect} to be a xsd:dayTimeDuration or +/-HH:MM" unless md
163163

lib/rdf/model/literal/time.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ def initialize(value, datatype: nil, lexical: nil, **options)
3939
end
4040
# Normalize 24:00:00 to 00:00:00
4141
hr, mi, se = tm.split(':')
42-
hr = "%.2i" % (hr.to_i % 24) if hr.to_i > 23
42+
if hr.to_i > 23
43+
hr = "%.2i" % (hr.to_i % 24)
44+
@string = nil
45+
end
4346
value = "#{hr}:#{mi}:#{se}"
4447
# Normalize to 1972-12-31 dateTime base
4548
::DateTime.parse("1972-12-31T#{hr}:#{mi}:#{se}#{@zone}")

lib/rdf/query/solution.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,13 +317,12 @@ def to_h
317317
def hash
318318
@bindings.hash
319319
end
320-
320+
321321
##
322322
# Equivalence of solution
323323
def eql?(other)
324324
other.is_a?(Solution) && @bindings.eql?(other.bindings)
325325
end
326-
alias_method :==, :eql?
327326

328327
##
329328
# Equals of solution

lib/rdf/query/solutions.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ def variable_names
7777
end
7878
end
7979

80+
##
81+
# Sets variable names used in these solutions. If not set, the default is determined by the variables used in each solution.
82+
#
83+
# @param [Array<Symbol, RDF::Query::Variable>] vars
84+
# @return [Array<Symbol>]
85+
def variable_names=(vars)
86+
@variable_names = vars.map(&:to_sym)
87+
end
88+
8089
##
8190
# @overload variable?
8291
# Returns `false`.
@@ -294,5 +303,17 @@ def limit(length)
294303
self
295304
end
296305
alias_method :limit!, :limit
306+
307+
##
308+
# Equivalence of solution
309+
def eql?(other)
310+
super && (!other.respond_to?(:variable_names) || variable_names.eql?(other.variable_names))
311+
end
312+
313+
##
314+
# Equals of solution
315+
def ==(other)
316+
super && (!other.respond_to?(:variable_names) || variable_names.eql?(other.variable_names))
317+
end
297318
end # Solutions
298319
end; end # RDF::Query

spec/query_solutions_spec.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,20 @@
305305
specify {is_expected.to include(:author, :age, :name, :description, :updated, :created, :title, :price, :date)}
306306
end
307307

308+
describe "#variable_names=" do
309+
it "can set variable names from constants" do
310+
solutions.variable_names = %i{author age foo}
311+
expect(solutions.variable_names).to include(:author, :age, :foo)
312+
expect(solutions.variable_names).not_to include(:name)
313+
end
314+
315+
it "can set variable names from variables" do
316+
solutions.variable_names = %w{author age foo}.map {|n| RDF::Query::Variable.new(n)}
317+
expect(solutions.variable_names).to include(:author, :age, :foo)
318+
expect(solutions.variable_names).not_to include(:name)
319+
end
320+
end
321+
308322
describe "#count" do
309323
its(:count) {is_expected.to eq 2}
310324
it "Counting the number of matching solutions" do
@@ -318,6 +332,40 @@
318332
end
319333
end
320334

335+
describe "#eql?" do
336+
it "is true for equivalent solutions" do
337+
expect(solutions).to eql solutions.dup
338+
end
339+
340+
it "is false for different solutions" do
341+
solns2 = RDF::Query::Solutions(uri)
342+
expect(solutions).not_to eql solns2
343+
end
344+
345+
it "is false for the same solution with different variable_names" do
346+
solns2 = solutions.dup
347+
solns2.variable_names = %i{foo bar}
348+
expect(solutions).not_to eql solns2
349+
end
350+
end
351+
352+
describe "#==" do
353+
it "is true for equivalent solutions" do
354+
expect(solutions).to eq solutions.dup
355+
end
356+
357+
it "is false for different solutions" do
358+
solns2 = RDF::Query::Solutions(uri)
359+
expect(solutions).not_to eq solns2
360+
end
361+
362+
it "is false for the same solution with different variable_names" do
363+
solns2 = solutions.dup
364+
solns2.variable_names = %i{foo bar}
365+
expect(solutions).not_to eq solns2
366+
end
367+
end
368+
321369
describe "#bindings" do
322370
subject {
323371
RDF::Query::Solutions(

0 commit comments

Comments
 (0)