This repository has been archived by the owner on May 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
app/services/geo_concerns/discovery/document_builder/slug_builder.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module GeoConcerns | ||
module Discovery | ||
class DocumentBuilder | ||
class SlugBuilder | ||
attr_reader :geo_concern | ||
|
||
def initialize(geo_concern) | ||
@geo_concern = geo_concern | ||
end | ||
|
||
def build(document) | ||
document.slug = slug | ||
end | ||
|
||
# Returns the document slug for use in discovery systems. | ||
# @return [String] document slug | ||
def slug | ||
identifier = geo_concern.identifier || geo_concern.id | ||
id = identifier.gsub(%r(ark:/\d{5}/), '') | ||
return id unless geo_concern.provenance | ||
"#{geo_concern.provenance.parameterize}-#{id}" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'rails_helper' | ||
|
||
describe GeoConcerns::Discovery::DocumentBuilder::SlugBuilder do | ||
subject { described_class.new(geo_concern_presenter) } | ||
|
||
let(:geo_concern_presenter) { GeoConcerns::VectorWorkShowPresenter.new(SolrDocument.new(geo_concern.to_solr), nil) } | ||
let(:geo_concern) { FactoryGirl.build(:vector_work, attributes) } | ||
let(:attributes) { { id: 'geo-work-1', | ||
title: ['Geo Work'], | ||
description: ['This is a Geo Work'], | ||
creator: ['Yosiwo George'], | ||
publisher: ['National Geographic'], | ||
spatial: ['Micronesia'], | ||
temporal: ['2011'], | ||
subject: ['Human settlements'], | ||
language: ['Esperanto'], | ||
identifier: ['ark:/99999/fk4'] | ||
} | ||
} | ||
|
||
describe 'vector work slug' do | ||
it 'uses ark noid fowlling the provenance' do | ||
expect(subject.slug).to eq('princeton-university-library-fk4') | ||
end | ||
end | ||
end |