Class: Source::Verbatim
- Inherits:
-
Source
- Object
- ActiveRecord::Base
- ApplicationRecord
- Source
- Source::Verbatim
- 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
- #nomenclature_date ⇒ Object
- #only_verbatim_is_populated ⇒ Ignored protected
- #reset_cached ⇒ Object protected
- #set_cached ⇒ Ignored protected
- #switch_type ⇒ Object protected
- #to_bibtex(user_id = nil) ⇒ Object protected
Methods inherited from Source
batch_create, batch_preview, #cited_objects, #clone, #is_bibtex?, #is_in_project?, #reject_project_sources, select_optimized, used_recently
Methods included from SoftValidation
#clear_soft_validations, #fix_soft_validations, #soft_fixed?, #soft_valid?, #soft_validate, #soft_validated?, #soft_validations
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::HasRoles
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
#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.
23 24 25 |
# File 'app/models/source/verbatim.rb', line 23 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 |
# File 'app/models/source/verbatim.rb', line 10 class Source::Verbatim < Source 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 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, 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 end |
Instance Method Details
#authority_name ⇒ Nil
34 35 36 |
# File 'app/models/source/verbatim.rb', line 34 def nil end |
#date ⇒ Nil
39 40 41 |
# File 'app/models/source/verbatim.rb', line 39 def date nil end |
#generate_bibtex ⇒ Source, Boolean
44 45 46 47 48 49 50 51 52 |
# File 'app/models/source/verbatim.rb', line 44 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 |
#nomenclature_date ⇒ Object
69 70 71 |
# File 'app/models/source/verbatim.rb', line 69 def nomenclature_date nil end |
#only_verbatim_is_populated ⇒ Ignored (protected)
111 112 113 114 115 116 |
# File 'app/models/source/verbatim.rb', line 111 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)
75 76 77 |
# File 'app/models/source/verbatim.rb', line 75 def reset_cached Source.find(id).send(:set_cached) end |
#set_cached ⇒ Ignored (protected)
106 107 108 |
# File 'app/models/source/verbatim.rb', line 106 def set_cached update_column(:cached, verbatim) end |
#switch_type ⇒ Object (protected)
96 97 98 99 100 101 102 103 |
# File 'app/models/source/verbatim.rb', line 96 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)
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'app/models/source/verbatim.rb', line 79 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 |