Skip to content

Commit

Permalink
rename encoded_thumb method in parser, and fix so it is accessible to…
Browse files Browse the repository at this point in the history
… indexers
  • Loading branch information
peetucket committed Oct 10, 2016
1 parent 080adfc commit 00841ad
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
6 changes: 6 additions & 0 deletions lib/discovery-indexer/reader/purlxml_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ class PurlxmlModel
# "oo000oo0001/pc0065_b08_f10_i031.jp2"
attr_accessor :thumb

# @!attribute [rw] thumb
# @return [String] a thumbnail image if it exists in the PURL, encoded as necessary
# @example
# "oo000oo0001%2Fpc0065_b08_f10_i031.jp2"
attr_accessor :encoded_thumb

# @!attribute [rw] sw_image_ids
# @return [Array] a list of the image ids and corresponding druids with %2F
# separator from the file and externalFile tags in the content_metadata
Expand Down
3 changes: 2 additions & 1 deletion lib/discovery-indexer/reader/purlxml_parser_strict.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def parse
purlxml_model.release_tags_hash = parse_release_tags_hash
purlxml_model.file_ids = parse_file_ids
purlxml_model.thumb = parse_thumb
purlxml_model.encoded_thumb = parse_encoded_thumb
purlxml_model.image_ids = parse_image_ids
purlxml_model.sw_image_ids = parse_sw_image_ids
purlxml_model.catkey = parse_catkey
Expand Down Expand Up @@ -161,7 +162,7 @@ def parse_thumb

# the thumbnail in publicXML properly URI encoded, including the slash separator
# @return [String] thumb filename with druid prepended, e.g. oo000oo0001%2Ffilename%20withspace.jp2
def encoded_thumb
def parse_encoded_thumb
thumb=parse_thumb
return unless thumb
thumb_druid=thumb.split('/').first # the druid (before the first slash)
Expand Down
8 changes: 4 additions & 4 deletions spec/discovery-indexer/reader/purlxml_parser_strict_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,25 +119,25 @@
it 'returns the thumb from publicxml' do
purlxml = described_class.new('tn629pk3948', @available_purl_xml_ng_doc)
expect(purlxml.send(:parse_thumb)).to eq 'tn629pk3948/tn629pk3948_thumb_1.jp2'
expect(purlxml.send(:encoded_thumb)).to eq 'tn629pk3948%2Ftn629pk3948_thumb_1.jp2'
expect(purlxml.send(:parse_encoded_thumb)).to eq 'tn629pk3948%2Ftn629pk3948_thumb_1.jp2'
end
it 'returns the first image when there is no thumb in publicxml' do
alternate_purl_xml_ng_doc = Nokogiri::XML(open('spec/fixtures/available_purl_xml_item_2.xml'), nil, 'UTF-8')
purlxml = described_class.new('druid:bg210vm0680', alternate_purl_xml_ng_doc)
expect(purlxml.send(:parse_thumb)).to eq 'bg210vm0680/bookCover.jp2'
expect(purlxml.send(:encoded_thumb)).to eq 'bg210vm0680%2FbookCover.jp2'
expect(purlxml.send(:parse_encoded_thumb)).to eq 'bg210vm0680%2FbookCover.jp2'
end
it 'returns the first image with an encoded space' do
alternate_purl_xml_ng_doc = Nokogiri::XML(open('spec/fixtures/available_purl_xml_item_image_with_space.xml'), nil, 'UTF-8')
purlxml = described_class.new('druid:bg210vm0680', alternate_purl_xml_ng_doc)
expect(purlxml.send(:parse_thumb)).to eq 'bg210vm0680/bookCover withspace.jp2'
expect(purlxml.send(:encoded_thumb)).to eq 'bg210vm0680%2FbookCover%20withspace.jp2'
expect(purlxml.send(:parse_encoded_thumb)).to eq 'bg210vm0680%2FbookCover%20withspace.jp2'
end
it 'returns nil when there are no images in publicxml' do
alternate_purl_xml_ng_doc = Nokogiri::XML(open('spec/fixtures/available_purl_xml_item_no_image.xml'), nil, 'UTF-8')
purlxml=described_class.new('bg210vm0680', alternate_purl_xml_ng_doc)
expect(purlxml.send(:parse_thumb)).to be_nil
expect(purlxml.send(:encoded_thumb)).to be_nil
expect(purlxml.send(:parse_encoded_thumb)).to be_nil
end
end

Expand Down
2 changes: 2 additions & 0 deletions spec/discovery-indexer/reader/purlxml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
expect(model.rights_metadata).to be_equivalent_to(@rights_metadata)
expect(model.rdf).to be_equivalent_to(@rdf)
expect(model.dc).to be_equivalent_to(@dc)
expect(model.thumb).to eq "tn629pk3948/tn629pk3948_img_1.jp2"
expect(model.encoded_thumb).to eq "tn629pk3948%2Ftn629pk3948_img_1.jp2"
end
end

Expand Down

0 comments on commit 00841ad

Please sign in to comment.