-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add chicago citation option * Refine chicago citation implementation * Update citation_string_processor.rb
- Loading branch information
Showing
8 changed files
with
95 additions
and
4 deletions.
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
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
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
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,32 @@ | ||
# frozen_string_literal: true | ||
require 'citeproc' | ||
require 'csl/styles' | ||
require './lib/citation_string_processor' | ||
|
||
class CitationFormatter | ||
include CitationStringProcessor | ||
attr_accessor :obj, :default_citations | ||
|
||
def initialize(obj) | ||
@obj = obj | ||
end | ||
|
||
def citation_for(style) | ||
CiteProc::Processor.new(style: style, format: 'html').import(item).render(:bibliography, id: :item).first | ||
end | ||
|
||
private | ||
|
||
def item | ||
CiteProc::Item.new({ | ||
"id": :item, | ||
"author": chicago_author(obj), | ||
"issued": obj[:pub_date_isim].first, | ||
"publisher": chicago_publisher(obj), | ||
"publisher-place": obj[:publisher_location_ssim]&.join(', '), | ||
"title": obj[:title_citation_ssi], | ||
"type": obj[:format_ssim]&.first&.downcase, | ||
"DOI": chicago_doi(obj) | ||
}) | ||
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 @@ | ||
# frozen_string_literal: true | ||
|
||
module CitationStringProcessor | ||
# Chicago Citation | ||
def chicago_author(obj) | ||
clean_end_punctuation(obj[:author_tesim]&.join(', ')) | ||
end | ||
|
||
def chicago_publisher(obj) | ||
publisher = obj[:published_tesim]&.first&.strip | ||
return nil if publisher.blank? | ||
|
||
publisher = publisher.gsub(/\[|\]/, '') | ||
clean_end_punctuation(publisher) if publisher.present? | ||
end | ||
|
||
def chicago_doi(obj) | ||
doi = obj['other_standard_ids_tesim']&.first&.strip | ||
clean_end_punctuation(doi) if doi.present? | ||
end | ||
|
||
# Helper Methods | ||
def clean_end_punctuation(text) | ||
[".", ",", ":", ";", "/"].include?(text[-1]) ? text[0...-1] : text | ||
end | ||
end |