Skip to content

Commit

Permalink
Finish 3.2.6
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Mar 14, 2022
2 parents 13bc125 + 6f9e254 commit 84063a9
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 8 deletions.
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
3.2.5
3.2.6
8 changes: 4 additions & 4 deletions lib/rdf/model/literal/temporal.rb
Expand Up @@ -128,7 +128,7 @@ def milliseconds?
#
# @return [String]
def to_s
@string || (@object.strftime(self.class.const_get(:FORMAT)).sub('.000', '') + self.tz)
@string ||= (@object.strftime(self.class.const_get(:FORMAT)).sub('.000', '') + self.tz)
end

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

Expand Down
5 changes: 4 additions & 1 deletion lib/rdf/model/literal/time.rb
Expand Up @@ -39,7 +39,10 @@ def initialize(value, datatype: nil, lexical: nil, **options)
end
# Normalize 24:00:00 to 00:00:00
hr, mi, se = tm.split(':')
hr = "%.2i" % (hr.to_i % 24) if hr.to_i > 23
if hr.to_i > 23
hr = "%.2i" % (hr.to_i % 24)
@string = nil
end
value = "#{hr}:#{mi}:#{se}"
# Normalize to 1972-12-31 dateTime base
::DateTime.parse("1972-12-31T#{hr}:#{mi}:#{se}#{@zone}")
Expand Down
3 changes: 1 addition & 2 deletions lib/rdf/query/solution.rb
Expand Up @@ -317,13 +317,12 @@ def to_h
def hash
@bindings.hash
end

##
# Equivalence of solution
def eql?(other)
other.is_a?(Solution) && @bindings.eql?(other.bindings)
end
alias_method :==, :eql?

##
# Equals of solution
Expand Down
21 changes: 21 additions & 0 deletions lib/rdf/query/solutions.rb
Expand Up @@ -77,6 +77,15 @@ def variable_names
end
end

##
# Sets variable names used in these solutions. If not set, the default is determined by the variables used in each solution.
#
# @param [Array<Symbol, RDF::Query::Variable>] vars
# @return [Array<Symbol>]
def variable_names=(vars)
@variable_names = vars.map(&:to_sym)
end

##
# @overload variable?
# Returns `false`.
Expand Down Expand Up @@ -294,5 +303,17 @@ def limit(length)
self
end
alias_method :limit!, :limit

##
# Equivalence of solution
def eql?(other)
super && (!other.respond_to?(:variable_names) || variable_names.eql?(other.variable_names))
end

##
# Equals of solution
def ==(other)
super && (!other.respond_to?(:variable_names) || variable_names.eql?(other.variable_names))
end
end # Solutions
end; end # RDF::Query
48 changes: 48 additions & 0 deletions spec/query_solutions_spec.rb
Expand Up @@ -305,6 +305,20 @@
specify {is_expected.to include(:author, :age, :name, :description, :updated, :created, :title, :price, :date)}
end

describe "#variable_names=" do
it "can set variable names from constants" do
solutions.variable_names = %i{author age foo}
expect(solutions.variable_names).to include(:author, :age, :foo)
expect(solutions.variable_names).not_to include(:name)
end

it "can set variable names from variables" do
solutions.variable_names = %w{author age foo}.map {|n| RDF::Query::Variable.new(n)}
expect(solutions.variable_names).to include(:author, :age, :foo)
expect(solutions.variable_names).not_to include(:name)
end
end

describe "#count" do
its(:count) {is_expected.to eq 2}
it "Counting the number of matching solutions" do
Expand All @@ -318,6 +332,40 @@
end
end

describe "#eql?" do
it "is true for equivalent solutions" do
expect(solutions).to eql solutions.dup
end

it "is false for different solutions" do
solns2 = RDF::Query::Solutions(uri)
expect(solutions).not_to eql solns2
end

it "is false for the same solution with different variable_names" do
solns2 = solutions.dup
solns2.variable_names = %i{foo bar}
expect(solutions).not_to eql solns2
end
end

describe "#==" do
it "is true for equivalent solutions" do
expect(solutions).to eq solutions.dup
end

it "is false for different solutions" do
solns2 = RDF::Query::Solutions(uri)
expect(solutions).not_to eq solns2
end

it "is false for the same solution with different variable_names" do
solns2 = solutions.dup
solns2.variable_names = %i{foo bar}
expect(solutions).not_to eq solns2
end
end

describe "#bindings" do
subject {
RDF::Query::Solutions(
Expand Down

0 comments on commit 84063a9

Please sign in to comment.