Class: ReferenceProcessor
- Inherits:
-
Object
- Object
- ReferenceProcessor
- Defined in:
- lib/reference_processor.rb
Overview
Class that add doi and canonical documents to references Later, we could add PMID and EID support
Instance Attribute Summary collapse
-
#reference ⇒ Object
readonly
Returns the value of attribute reference.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
-
#check_doi(doi) ⇒ Object
Change doi to correct format WOS references have several problems with DOI.
-
#initialize(reference) ⇒ ReferenceProcessor
constructor
A new instance of ReferenceProcessor.
-
#process_doi ⇒ Object
If reference text have a doi inside, add that to object assign a canonical document if exists.
Constructor Details
#initialize(reference) ⇒ ReferenceProcessor
Returns a new instance of ReferenceProcessor.
33 34 35 36 |
# File 'lib/reference_processor.rb', line 33 def initialize(reference) @reference=reference @result=Result.new end |
Instance Attribute Details
#reference ⇒ Object (readonly)
Returns the value of attribute reference.
32 33 34 |
# File 'lib/reference_processor.rb', line 32 def reference @reference end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
32 33 34 |
# File 'lib/reference_processor.rb', line 32 def result @result end |
Instance Method Details
#check_doi(doi) ⇒ Object
Change doi to correct format WOS references have several problems with DOI
39 40 41 42 43 44 |
# File 'lib/reference_processor.rb', line 39 def check_doi(doi) if doi and doi=~/(10.+?);(unstructured|author|volume)/ doi=$1 end doi end |
#process_doi ⇒ Object
If reference text have a doi inside, add that to object assign a canonical document if exists
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/reference_processor.rb', line 47 def process_doi if @reference.text =~/\b(10[.][0-9]{4,}(?:[.][0-9]+)*\/(?:(?!["&\'<>])\S)+)\b/ doi=check_doi($1) update_fields={:doi=>doi} cd=CanonicalDocument[:doi => doi] update_fields[:canonical_document_id]=cd[:id] if cd @reference.update(update_fields) @result.success(I18n::t(:Reference_with_new_doi, reference_id:@reference[:id], doi:doi)) true else false end end |