Skip to content

Commit

Permalink
Finish 3.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Dec 30, 2017
2 parents 5b1ad24 + cea7191 commit 7c7ad14
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.0
3.0.1
7 changes: 5 additions & 2 deletions lib/rdf/format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class Format
# Only return a format having a writer.
# @param [String, Proc] sample (nil)
# A sample of input used for performing format detection. If we find no formats, or we find more than one, and we have a sample, we can perform format detection to find a specific format to use, in which case we pick the last one we find
# @param [Boolean] all_if_none (true)
# Returns all formats if none match, otherwise no format. Note that having a `sample` overrides this, and will search through all formats, or all those filtered to find a sample that matches
# @yield [klass]
# @yieldparam [Class]
# @return [Enumerator]
Expand All @@ -74,6 +76,7 @@ def self.each(file_name: nil,
has_reader: false,
has_writer: false,
sample: nil,
all_if_none: true,
**options,
&block)
formats = case
Expand Down Expand Up @@ -106,7 +109,7 @@ def self.each(file_name: nil,
when file_extension
file_extensions[file_extension.to_sym]
else
@@subclasses
all_if_none ? @@subclasses : nil
end || (sample ? @@subclasses : []) # If we can sample, check all classes

# Subset by available reader or writer
Expand Down Expand Up @@ -181,7 +184,7 @@ def self.for(*args, **options, &block)
end
classes
else
self.each(options).to_a
self.each(options.merge(all_if_none: false)).to_a
end

# Return the last detected format
Expand Down
4 changes: 3 additions & 1 deletion lib/rdf/vocabulary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,11 @@ def expand_pname(pname)
# @param [RDF::URI] uri
# @return [Vocabulary]
def find(uri)
uri = RDF::URI(uri) if uri.is_a?(String)
return nil unless uri.uri? && uri.valid?
RDF::Vocabulary.detect do |v|
if uri.length >= v.to_uri.length
RDF::URI(uri).start_with?(v.to_uri)
uri.start_with?(v.to_uri)
else
v.to_uri.to_s.sub(%r([/#]$), '') == uri.to_s
end
Expand Down
4 changes: 4 additions & 0 deletions spec/format_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ def self.to_sym; :foo_bar; end
end
end

it "returns no formats if none match" do
expect(RDF::Format.for).to be_nil
end

it "returns any format for content_type: */*" do
expect(RDF::Format.for(content_type: '*/*')).to be_a(Class)
end
Expand Down
10 changes: 10 additions & 0 deletions spec/vocabulary_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,16 @@
expect(RDF::Vocabulary.find(term.to_s)).to equal vocab
end
end
it "returns nil if argument is a BNode" do
terms.each do |term, vocab|
expect(RDF::Vocabulary.find(RDF::Node.new("a"))).to be_nil
end
end
it "returns nil if argument an invalid URI" do
terms.each do |term, vocab|
expect(RDF::Vocabulary.find("a b c")).to be_nil
end
end
end

describe ".find_term" do
Expand Down

0 comments on commit 7c7ad14

Please sign in to comment.