Skip to content

Commit

Permalink
Merge pull request #88 from datacite/sizes-and-formats
Browse files Browse the repository at this point in the history
Sizes and formats
  • Loading branch information
Martin Fenner authored May 3, 2020
2 parents 4317168 + 4d2754d commit faddefb
Show file tree
Hide file tree
Showing 8 changed files with 248 additions and 14 deletions.
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
bolognese (1.5.19)
bolognese (1.5.20)
activesupport (>= 4.2.5)
benchmark_methods (~> 0.7)
bibtex-ruby (>= 5.1.0)
Expand Down Expand Up @@ -148,15 +148,15 @@ GEM
rspec-core (~> 3.9.0)
rspec-expectations (~> 3.9.0)
rspec-mocks (~> 3.9.0)
rspec-core (3.9.1)
rspec-support (~> 3.9.1)
rspec-core (3.9.2)
rspec-support (~> 3.9.3)
rspec-expectations (3.9.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-mocks (3.9.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-support (3.9.2)
rspec-support (3.9.3)
rspec-xsd (0.1.0)
nokogiri (~> 1.6)
rspec (~> 3)
Expand Down
22 changes: 20 additions & 2 deletions lib/bolognese/datacite_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ def insert_work(xml)
insert_publisher(xml)
insert_publication_year(xml)
insert_resource_type(xml)
insert_alternate_identifiers(xml)
insert_subjects(xml)
insert_language(xml)
insert_contributors(xml)
insert_dates(xml)
insert_language(xml)
insert_alternate_identifiers(xml)
insert_related_identifiers(xml)
insert_sizes(xml)
insert_formats(xml)
insert_version(xml)
insert_rights_list(xml)
insert_descriptions(xml)
Expand Down Expand Up @@ -201,6 +203,22 @@ def insert_related_identifiers(xml)
end
end

def insert_sizes(xml)
xml.sizes do
Array.wrap(sizes).each do |s|
xml.size(s)
end
end
end

def insert_formats(xml)
xml.formats do
Array.wrap(formats).each do |f|
xml.format(f)
end
end
end

def insert_rights_list(xml)
return xml unless rights_list.present?

Expand Down
2 changes: 1 addition & 1 deletion lib/bolognese/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Bolognese
VERSION = "1.5.19"
VERSION = "1.5.20"
end
34 changes: 27 additions & 7 deletions spec/datacite_utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@
end
end

# context "insert_dates" do
# it "insert" do
# xml = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') { |xml| subject.insert_dates(xml) }.to_xml
# response = Maremma.from_xml(xml)
# expect(response.dig("dates", "date")).to eq("dateType"=>"Issued", "__content__"=>"2011")
# end
# end
context "insert_dates" do
it "insert" do
xml = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') { |xml| subject.insert_dates(xml) }.to_xml
response = Maremma.from_xml(xml)
expect(response.dig("dates", "date")).to eq([{"__content__"=>"2011-02-01T17:22:41Z", "dateType"=>"Available"}, {"__content__"=>"2011", "dateType"=>"Issued"}])
end
end

context "insert_subjects" do
it "insert" do
Expand All @@ -113,6 +113,26 @@
end
end

context "insert_sizes" do
it "insert" do
xml = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') { |xml| subject.insert_sizes(xml) }.to_xml
response = Maremma.from_xml(xml)
expect(response.fetch("sizes", nil)).to eq("size"=>"107328 bytes")
end
end

context "insert_formats" do
let(:input) { IO.read(fixture_path + 'datacite-empty-sizes.xml') }

subject { Bolognese::Metadata.new(input: input, from: "datacite") }

it "insert" do
xml = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') { |xml| subject.insert_formats(xml) }.to_xml
response = Maremma.from_xml(xml)
expect(response.fetch("formats", nil)).to eq("format" => "text")
end
end

context "insert_language" do
it "insert" do
xml = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') { |xml| subject.insert_language(xml) }.to_xml
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

0 comments on commit faddefb

Please sign in to comment.