Class: Source::Verbatim

Inherits:
Source show all
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

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

ALTERNATE_VALUES_FOR

Constants included from SoftValidation

SoftValidation::ANCESTORS_WITH_SOFT_VALIDATIONS

Instance Attribute Summary (collapse)

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, #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

#by

Instance Method Summary (collapse)

Methods inherited from Source

batch_create, batch_preview, #cited_objects, #is_bibtex?, #is_in_project?, new_from_citation, new_from_doi, #reject_project_sources

Methods included from SoftValidation

#clear_soft_validations, #fix_soft_validations, #soft_fixed?, #soft_valid?, #soft_validate, #soft_validated?, #soft_validations

Methods included from Housekeeping::Timestamps

#data_breakdown_for_chartkick_recent

Methods included from Housekeeping::Users

#set_created_by_id, #set_updated_by_id

Methods included from ActiverecordUtilities

#trim_attributes

Instance Attribute Details

- (String) verbatim

This is the only valid attribute of Source::Verbatim. It is the verbatim representation of the source.

Returns:

  • (String)


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
# 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

  validates_presence_of :verbatim
  validate :only_verbatim_is_populated

  # @return [Nil]
  def authority_name
    nil
  end

  # @return [Nil]
  def date
    nil
  end

  # @return [Source, Boolean]
  def generate_bibtex
    return false if self.verbatim.blank?
    result = Source.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

  protected

  # @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

- (Nil) authority_name

Returns:

  • (Nil)


26
27
28
# File 'app/models/source/verbatim.rb', line 26

def authority_name
  nil
end

- (Nil) date

Returns:

  • (Nil)


31
32
33
# File 'app/models/source/verbatim.rb', line 31

def date
  nil
end

- (Source, Boolean) generate_bibtex

Returns:



36
37
38
39
40
41
42
43
44
# File 'app/models/source/verbatim.rb', line 36

def generate_bibtex
  return false if self.verbatim.blank?
  result = Source.new_from_citation(citation: verbatim)
  if result.type == 'Source::Bibtex'
    result
  else
    false
  end
end

- (Ignored) only_verbatim_is_populated (protected)

Returns:

  • (Ignored)


66
67
68
69
70
71
# File 'app/models/source/verbatim.rb', line 66

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

- (Ignored) set_cached (protected)

Returns:

  • (Ignored)


61
62
63
# File 'app/models/source/verbatim.rb', line 61

def set_cached
  update_column(:cached, verbatim)
end