Skip to content

Commit 4311460

Browse files
committed
Release 2.0.2
2 parents 78b2de6 + 90234fa commit 4311460

8 files changed

Lines changed: 91 additions & 15 deletions

File tree

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ env:
66
rvm:
77
- 2.0
88
- 2.1
9-
- 2.2.4
9+
- 2.2.5
1010
- 2.3.1
11-
- jruby-9.0.4.0
12-
- rbx-2
11+
- jruby-9.0.5.0
12+
- rbx
1313
cache: bundler
1414
sudo: false
1515
addons:

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.1
1+
2.0.2

lib/rdf/model/list.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,13 @@ def valid?
139139
# @return [RDF::Graph] the underlying graph storing the statements that constitute this list
140140
attr_reader :graph
141141

142+
##
143+
# @see RDF::Value#==
144+
def ==(other)
145+
return false if other.is_a?(RDF::Value) && !other.list?
146+
super
147+
end
148+
142149
##
143150
# Returns the set intersection of this list and `other`.
144151
#
@@ -272,7 +279,7 @@ def [](index)
272279
# a[3, 0] = "B" #=> [1, 2, "A", "B"]
273280
#
274281
# @overload []=(index, term)
275-
# Replaces the element at `index` with `term`.
282+
# Replaces the element at `index` with `term`.
276283
# @param [Integer] index
277284
# @param [RDF::Term] term
278285
# A non-RDF::Term is coerced to a Literal.
@@ -445,7 +452,7 @@ def eql?(other)
445452
# @return [Integer]
446453
# @see http://ruby-doc.org/core-2.2.2/Array.html#method-i-3C-3D-3E
447454
def <=>(other)
448-
to_a <=> other.to_a # TODO: optimize this
455+
to_a <=> Array(other)
449456
end
450457

451458
##

lib/rdf/model/statement.rb

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def statement?
135135
#
136136
# @return [Boolean]
137137
def variable?
138-
!(has_subject? && subject.resource? &&
138+
!(has_subject? && subject.resource? &&
139139
has_predicate? && predicate.resource? &&
140140
has_object? && (object.resource? || object.literal?) &&
141141
(has_graph? ? graph_name.resource? : true ))
@@ -150,7 +150,7 @@ def invalid?
150150
##
151151
# @return [Boolean]
152152
def valid?
153-
has_subject? && subject.resource? && subject.valid? &&
153+
has_subject? && subject.resource? && subject.valid? &&
154154
has_predicate? && predicate.uri? && predicate.valid? &&
155155
has_object? && object.term? && object.valid? &&
156156
(has_graph? ? graph_name.resource? && graph_name.valid? : true )
@@ -228,22 +228,61 @@ def node?
228228
alias_method :has_blank_nodes?, :node?
229229

230230
##
231+
# Checks statement equality as a quad.
232+
#
231233
# @param [Statement] other
232234
# @return [Boolean]
235+
#
236+
# @see RDF::URI#==
237+
# @see RDF::Node#==
238+
# @see RDF::Literal#==
239+
# @see RDF::Query::Variable#==
233240
def eql?(other)
234241
other.is_a?(Statement) && self == other && (self.graph_name || false) == (other.graph_name || false)
235242
end
236243

237244
##
245+
# Checks statement equality as a triple.
246+
#
238247
# @param [Object] other
239248
# @return [Boolean]
249+
#
250+
# @see RDF::URI#==
251+
# @see RDF::Node#==
252+
# @see RDF::Literal#==
253+
# @see RDF::Query::Variable#==
240254
def ==(other)
241-
to_a == Array(other)
255+
to_a == Array(other) &&
256+
!(other.is_a?(RDF::Value) && other.list?)
242257
end
243258

244259
##
260+
# Checks statement equality with patterns.
261+
#
262+
# Uses `#eql?` to compare each of `#subject`, `#predicate`, `#object`, and
263+
# `#graph_name` to those of `other`. Any statement part which is not
264+
# present in `self` is ignored.
265+
#
266+
# @example
267+
# statement = RDF::Statement.new(RDF::URI('s'), RDF::URI('p'), RDF::URI('o'))
268+
# pattern = RDF::Statement.new(RDF::URI('s'), RDF::URI('p'), RDF::Query::Variable.new)
269+
#
270+
# # true
271+
# statement === statement
272+
# pattern === statement
273+
# RDF::Statement.new(nil, nil, nil) === statement
274+
#
275+
# # false
276+
# statement === pattern
277+
# statement === RDF::Statement.new(nil, nil, nil)
278+
#
245279
# @param [Statement] other
246280
# @return [Boolean]
281+
#
282+
# @see RDF::URI#eql?
283+
# @see RDF::Node#eql?
284+
# @see RDF::Literal#eql?
285+
# @see RDF::Query::Variable#eql?
247286
def ===(other)
248287
return false if has_object? && !object.eql?(other.object)
249288
return false if has_predicate? && !predicate.eql?(other.predicate)

lib/rdf/model/uri.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ def canonicalize!
377377
@object = {
378378
scheme: normalized_scheme,
379379
authority: normalized_authority,
380-
path: normalized_path.sub(/\/+/, '/'),
380+
path: normalized_path.squeeze('/'),
381381
query: normalized_query,
382382
fragment: normalized_fragment
383383
}
@@ -887,7 +887,7 @@ def scheme=(value)
887887
# Return normalized version of scheme, if any
888888
# @return [String]
889889
def normalized_scheme
890-
scheme.strip.downcase if scheme
890+
normalize_segment(scheme.strip, SCHEME, true) if scheme
891891
end
892892

893893
##
@@ -965,7 +965,7 @@ def host=(value)
965965
# @return [String]
966966
def normalized_host
967967
# Remove trailing '.' characters
968-
normalize_segment(host, IHOST, true).sub(/\.*$/, '') if host
968+
normalize_segment(host, IHOST, true).chomp('.') if host
969969
end
970970

971971
##
@@ -1059,7 +1059,7 @@ def normalized_path
10591059

10601060
res = self.class.normalize_path(norm_segs.join("/"))
10611061
# Special rules for specific protocols having empty paths
1062-
res.empty? ? (%w(http https ftp tftp).include?(normalized_scheme) ? '/' : "") : res
1062+
normalize_segment(res.empty? ? (%w(http https ftp tftp).include?(normalized_scheme) ? '/' : "") : res, IHIER_PART)
10631063
end
10641064

10651065
##
@@ -1134,9 +1134,9 @@ def authority=(value)
11341134
# @return [String]
11351135
def normalized_authority
11361136
if authority
1137-
(userinfo ? "#{normalized_userinfo}@" : "") +
1137+
(userinfo ? normalized_userinfo.to_s + "@" : "") +
11381138
normalized_host.to_s +
1139-
(normalized_port ? ":#{normalized_port}" : "")
1139+
(normalized_port ? ":" + normalized_port.to_s : "")
11401140
end
11411141
end
11421142

spec/model_list_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,10 @@
571571
it "returns 0 when given the same list" do
572572
expect(ten).to eq ten
573573
end
574+
575+
it "returns 0 when given the same list as array" do
576+
expect(ten).to eq ten.to_a
577+
end
574578
end
575579

576580
describe "#==" do
@@ -585,6 +589,22 @@
585589
it "returns true when comparing a list to its contents" do
586590
expect(ten).to eq ten.to_a
587591
end
592+
593+
it "returns false when comparing to non-list Values" do
594+
expect(ten).not_to eq ten.subject
595+
expect(ten).not_to eq ten.statements.first
596+
expect(ten).not_to eq RDF::Node.new
597+
expect(ten).not_to eq RDF::Graph.new
598+
expect(ten).not_to eq RDF::Literal.new('')
599+
expect(ten).not_to eq Object.new
600+
end
601+
602+
it "returns false when comparing to similar statements" do
603+
statement = RDF::Statement(:s, :p, :o)
604+
quasistatement = RDF::List[:s, :p, :o]
605+
606+
expect(quasistatement).not_to eq statement
607+
end
588608
end
589609

590610
describe "#empty?" do

spec/model_statement_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@
207207
expect(subject).not_to equal RDF::Statement.new s, p, o
208208
expect(subject).to equal subject
209209
end
210+
211+
it "is not == a RDF::List" do
212+
expect(subject).not_to eq RDF::List[*subject]
213+
end
210214
end
211215

212216
context "completness" do

spec/model_uri_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,12 @@
477477
expect(u1.canonicalize!.to_s).to eq u2.to_s
478478
expect(u1).to eq u2
479479
end
480+
it "#canonicalize does not fail with Encoding::CompatibilityError on weird IRIs" do
481+
u1 = RDF::URI "htЫtp://user:passoЫd@exaЫmple.com:8080/path ПУТЬ?queЫry=valЫue#fragmeЫnt"
482+
u2 = RDF::URI "ht%D0%ABtp://user:passoЫd@exaЫmple.com:8080/path%20ПУТЬ?queЫry=valЫue#fragmeЫnt"
483+
expect(u1.canonicalize.to_s.dup.force_encoding(u2.to_s.encoding)).to eq u2.to_s
484+
expect(u1).to eq u1
485+
end
480486
end
481487

482488
describe "#/" do

0 commit comments

Comments
 (0)