Class: Source::Verbatim
- Inherits:
-
Source
- Object
- ActiveRecord::Base
- ApplicationRecord
- Source
- Source::Verbatim
- Includes:
- Shared::OriginRelationship
- Defined in:
- app/models/source/verbatim.rb
Overview
Verbatim - Subclass of Source that represents a pasted copy of a reference. This class is provided to support rapid data entry for later normalization. Once the Source::Verbatim information has been broken down into a a valid Source::Bibtex or Source:Human, the verbatim source is no longer available.
Constant Summary collapse
- IGNORE_IDENTICAL =
[:serial_id, :address, :annote, :booktitle, :chapter, :crossref, :edition, :editor, :howpublished, :institution, :journal, :key, :month, :note, :number, :organization, :pages, :publisher, :school, :series, :title, :volume, :doi, :abstract, :copyright, :language, :stated_year, :bibtex_type, :day, :year, :isbn, :issn, :verbatim_contents, :verbatim_keywords, :language_id, :translator, :year_suffix, :url, :author, :cached, :cached_author_string, :cached_nomenclature_date].freeze
- IGNORE_SIMILAR =
IGNORE_IDENTICAL.dup.freeze
Constants inherited from Source
Constants included from SoftValidation
SoftValidation::ANCESTORS_WITH_SOFT_VALIDATIONS
Instance Attribute Summary collapse
-
#convert_to_bibtex ⇒ Object
Returns the value of attribute convert_to_bibtex.
-
#verbatim ⇒ String
This is the only valid attribute of Source::Verbatim.
Attributes inherited from Source
#abstract, #address, #annote, #author, #bibtex_type, #booktitle, #cached, #cached_author_string, #cached_nomenclature_date, #chapter, #copyright, #crossref, #day, #doi, #edition, #editor, #howpublished, #institution, #isbn, #issn, #journal, #key, #language, #language_id, #month, #no_year_suffix_validation, #note, #number, #organization, #pages, #publisher, #school, #serial_id, #series, #stated_year, #title, #translator, #type, #url, #verbatim_contents, #verbatim_keywords, #volume, #year, #year_suffix
Attributes included from Housekeeping::Users
Instance Method Summary collapse
- #authority_name ⇒ Nil
- #date ⇒ Nil
- #generate_bibtex ⇒ Source, Boolean
- #get_cached ⇒ Object protected
- #nomenclature_date ⇒ Object
- #only_verbatim_is_populated ⇒ Ignored protected
- #reset_cached ⇒ Object protected
- #set_cached ⇒ Ignored protected
-
#sv_cached_names ⇒ Object
protected
this cannot be moved to soft_validation_extensions.
- #switch_type ⇒ Object protected
- #to_bibtex(user_id = nil) ⇒ Object protected
Methods included from Shared::OriginRelationship
#new_objects, #old_objects, #reject_origin_relationships, #set_origin
Methods inherited from Source
#author_year, batch_create, batch_preview, #cited_objects, #clone, #is_bibtex?, #is_in_project?, #reject_project_sources, select_optimized, #sv_fix_cached_names, #sv_fix_stated_year, #sv_html_tags, #sv_stated_year, used_recently
Methods included from SoftValidation
#clear_soft_validations, #fix_for, #fix_soft_validations, #soft_fixed?, #soft_valid?, #soft_validate, #soft_validated?, #soft_validations, #soft_validators
Methods included from Shared::HasPapertrail
#attribute_updated, #attribute_updater
Methods included from Shared::IsData
#errors_excepting, #full_error_messages_excepting, #identical, #is_community?, #is_destroyable?, #is_editable?, #is_in_use?, #is_in_users_projects?, #metamorphosize, #similar
Methods included from Shared::Documentation
#document_array=, #documented?, #reject_documentation, #reject_documents
Methods included from Shared::Tags
#reject_tags, #tag_with, #tagged?, #tagged_with?
Methods included from Shared::Notes
#concatenated_notes_string, #reject_notes
Methods included from Shared::Identifiers
#dwc_occurrence_id, #identified?, #next_by_identifier, #previous_by_identifier, #reject_identifiers
Methods included from Shared::DataAttributes
#import_attributes, #internal_attributes, #keyword_value_hash, #reject_data_attributes
Methods included from Shared::AlternateValues
#all_values_for, #alternate_valued?
Methods included from Housekeeping::Timestamps
#data_breakdown_for_chartkick_recent
Methods included from Housekeeping::Users
#set_created_by_id, #set_updated_by_id
Methods inherited from ApplicationRecord
Instance Attribute Details
#convert_to_bibtex ⇒ Object
Returns the value of attribute convert_to_bibtex.
27 28 29 |
# File 'app/models/source/verbatim.rb', line 27 def convert_to_bibtex @convert_to_bibtex end |
#verbatim ⇒ String
This is the only valid attribute of Source::Verbatim. It is the verbatim representation of the source.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'app/models/source/verbatim.rb', line 10 class Source::Verbatim < Source include Shared::OriginRelationship IGNORE_IDENTICAL = [:serial_id, :address, :annote, :booktitle, :chapter, :crossref, :edition, :editor, :howpublished, :institution, :journal, :key, :month, :note, :number, :organization, :pages, :publisher, :school, :series, :title, :volume, :doi, :abstract, :copyright, :language, :stated_year, :bibtex_type, :day, :year, :isbn, :issn, :verbatim_contents, :verbatim_keywords, :language_id, :translator, :year_suffix, :url, :author, :cached, :cached_author_string, :cached_nomenclature_date].freeze IGNORE_SIMILAR = IGNORE_IDENTICAL.dup.freeze is_origin_for 'Source::Bibtex', 'Source::Verbatim' originates_from 'Source::Bibtex', 'Source::Verbatim' attr_accessor :convert_to_bibtex before_validation :to_bibtex, if: -> { convert_to_bibtex } before_validation :switch_type, if: -> { persisted? && (type != 'Source::Verbatim') } after_save :reset_cached, if: -> { type != 'Source::Verbatim' } validates_presence_of :verbatim, if: -> { type == 'Source::Verbatim' } validate :only_verbatim_is_populated, if: -> { type == 'Source::Verbatim' } # @return [Nil] def nil end # @return [Nil] def date nil end # @return [Source, Boolean] def generate_bibtex return false if verbatim.blank? result = TaxonWorks::Vendor::Serrano.new_from_citation(citation: verbatim) if result.type == 'Source::Bibtex' result else false end end # @param [Source] source # @return [Boolean] # def similar(source) # false # end # @param [Source] source # @return [Boolean] # def identical(source) # false # end # @retun [nil] # verbatim sources do not have nomenclature dates, but this method is used in catalogs def nomenclature_date nil end protected def reset_cached Source.find(id).send(:set_cached) end def to_bibtex(user_id = nil) user_id = updated_by_id if user_id.nil? if a = generate_bibtex if a.valid? b = a.attributes %w{id created_at updated_at created_by_id updated_by_id}.each do |c| b.delete(c) end b.merge(updated_at: Time.now, updated_by_id: user_id) update_columns(b) end else false end end def switch_type if Source.new(attributes).valid? update_column(:type, type) else errors.add(:base, 'conversion has invalid attributes') end end # @return [Ignored] def set_cached update_column(:cached, get_cached) end def get_cached verbatim end # @return [Ignored] def only_verbatim_is_populated self.attributes.each do |k, v| next if %w{id type cached verbatim created_by_id updated_by_id created_at updated_at}.include?(k) errors.add(k, 'can not be provided to a verbatim reference') if !v.blank? end end def sv_cached_names # this cannot be moved to soft_validation_extensions soft_validations.add( :base, 'Cached values should be updated', success_message: 'Cached values were updated', failure_message: 'Failed to update cached values') if cached != verbatim end end |
Instance Method Details
#authority_name ⇒ Nil
38 39 40 |
# File 'app/models/source/verbatim.rb', line 38 def nil end |
#date ⇒ Nil
43 44 45 |
# File 'app/models/source/verbatim.rb', line 43 def date nil end |
#generate_bibtex ⇒ Source, Boolean
48 49 50 51 52 53 54 55 56 |
# File 'app/models/source/verbatim.rb', line 48 def generate_bibtex return false if verbatim.blank? result = TaxonWorks::Vendor::Serrano.new_from_citation(citation: verbatim) if result.type == 'Source::Bibtex' result else false end end |
#get_cached ⇒ Object (protected)
114 115 116 |
# File 'app/models/source/verbatim.rb', line 114 def get_cached verbatim end |
#nomenclature_date ⇒ Object
73 74 75 |
# File 'app/models/source/verbatim.rb', line 73 def nomenclature_date nil end |
#only_verbatim_is_populated ⇒ Ignored (protected)
119 120 121 122 123 124 |
# File 'app/models/source/verbatim.rb', line 119 def only_verbatim_is_populated self.attributes.each do |k, v| next if %w{id type cached verbatim created_by_id updated_by_id created_at updated_at}.include?(k) errors.add(k, 'can not be provided to a verbatim reference') if !v.blank? end end |
#reset_cached ⇒ Object (protected)
79 80 81 |
# File 'app/models/source/verbatim.rb', line 79 def reset_cached Source.find(id).send(:set_cached) end |
#set_cached ⇒ Ignored (protected)
110 111 112 |
# File 'app/models/source/verbatim.rb', line 110 def set_cached update_column(:cached, get_cached) end |
#sv_cached_names ⇒ Object (protected)
this cannot be moved to soft_validation_extensions
126 127 128 129 130 131 |
# File 'app/models/source/verbatim.rb', line 126 def sv_cached_names # this cannot be moved to soft_validation_extensions soft_validations.add( :base, 'Cached values should be updated', success_message: 'Cached values were updated', failure_message: 'Failed to update cached values') if cached != verbatim end |
#switch_type ⇒ Object (protected)
100 101 102 103 104 105 106 107 |
# File 'app/models/source/verbatim.rb', line 100 def switch_type if Source.new(attributes).valid? update_column(:type, type) else errors.add(:base, 'conversion has invalid attributes') end end |
#to_bibtex(user_id = nil) ⇒ Object (protected)
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/models/source/verbatim.rb', line 83 def to_bibtex(user_id = nil) user_id = updated_by_id if user_id.nil? if a = generate_bibtex if a.valid? b = a.attributes %w{id created_at updated_at created_by_id updated_by_id}.each do |c| b.delete(c) end b.merge(updated_at: Time.now, updated_by_id: user_id) update_columns(b) end else false end end |