-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from mlibrary/remove_punctuation_from_browse_s…
…tring Clean up the user-submitted author browse string
- Loading branch information
Showing
3 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
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
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,43 @@ | ||
module StringCleaner | ||
def self.prefixes | ||
# are there more of these? | ||
[ | ||
"academic_discipline", | ||
"author", | ||
"call_number_starts_with", | ||
"contains", | ||
"contributor", | ||
"date", | ||
"isbn", | ||
"isn", | ||
"issn", | ||
"journal_title", | ||
"keyword", | ||
"pmid", | ||
"publication_date", | ||
"publisher", | ||
"realuth", | ||
"series", | ||
"subject", | ||
"title", | ||
"title_starts_with" | ||
] | ||
end | ||
|
||
def self.strip_symbols(str) | ||
# str.gsub(/[\p{P}\p{Sm}\p{Sc}\p{So}^`]/, "") | ||
str.gsub(/["']/, "") | ||
end | ||
|
||
# TODO: add bits to remove field prefix (e.g., 'author:') as defined in 00-catalog.yml | ||
# this is where the author browse specific cleaning goes | ||
def self.cleanup_author_browse_string(str) | ||
prefixes.each do |x| | ||
if str.match?(/^#{x}:/) | ||
str.sub!(/^#{x}:/, "") | ||
break | ||
end | ||
end | ||
strip_symbols(str) | ||
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,15 @@ | ||
describe StringCleaner do | ||
context ".strip_symbols" do | ||
it "removes certain punctuation" do | ||
expect(described_class.strip_symbols('"\'')).to eq("") | ||
end | ||
end | ||
context ".cleanup_author_browse_string" do | ||
it "removes 'author:' prefix" do | ||
expect(described_class.cleanup_author_browse_string('author:"Author Name"')).to eq("Author Name") | ||
end | ||
it "removes 'isn(' prefix" do | ||
expect(described_class.cleanup_author_browse_string("isn:(123-456)")).to eq("(123-456)") | ||
end | ||
end | ||
end |