Class: Source::Verbatim

Inherits:
Source
  • Object
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

Constant Summary

Constants inherited from Source

ALTERNATE_VALUES_FOR

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, find_for_autocomplete, generate_download, #is_bibtex?, #nearest_by_levenshtein, new_from_citation, new_from_doi, #reject_project_sources

Methods included from Housekeeping::Timestamps

#data_breakdown_for_chartkick_recent

Methods included from Housekeeping::Users

#set_created_by_id, #set_updated_by_id

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
# File 'app/models/source/verbatim.rb', line 10

class Source::Verbatim < Source
 
  validates_presence_of :verbatim
  validate :only_verbatim_is_populated

  def authority_name
    nil
  end

  def date
    nil
  end

  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

  protected

  def set_cached
    self.cached = self.verbatim
  end

  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

- (Object) authority_name



15
16
17
# File 'app/models/source/verbatim.rb', line 15

def authority_name
  nil
end

- (Object) date



19
20
21
# File 'app/models/source/verbatim.rb', line 19

def date
  nil
end

- (Object) generate_bibtex



23
24
25
26
27
28
29
30
31
# File 'app/models/source/verbatim.rb', line 23

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

- (Object) only_verbatim_is_populated (protected)



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

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

- (Object) set_cached (protected)



35
36
37
# File 'app/models/source/verbatim.rb', line 35

def set_cached
  self.cached = self.verbatim
end