Class: Source::Human

Inherits:
Source show all
Defined in:
app/models/source/human.rb

Overview

A human source can be either a single individual person or a group of people (e.g. Tom, Dick and Harry decided that this species is the same as that but haven’t written it up yet.)

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, :verbatim, :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

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, #verbatim_contents, #verbatim_keywords, #volume, #year, #year_suffix

Attributes included from Housekeeping::Users

#by

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Source

#author_year, batch_create, batch_preview, #cited_objects, #clone, #is_bibtex?, #is_in_project?, #nomenclature_date, #reject_project_sources, select_optimized, #sv_fix_cached_names, #sv_fix_stated_year, #sv_html_tags, #sv_stated_year, used_recently

Methods included from Shared::IsData

#errors_excepting, #full_error_messages_excepting, #is_community?, #is_destroyable?, #is_editable?, #is_in_use?, #is_in_users_projects?, #metamorphosize

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::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, #uri, #uuid

Methods included from Shared::Documentation

#document_array=, #documented?, #reject_documentation, #reject_documents

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::Users

#set_created_by_id, #set_updated_by_id

Methods inherited from ApplicationRecord

transaction_with_retry

Class Method Details

.by_person(person_ids = [ ], table_alias = nil) ⇒ Object



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

def self.by_person(person_ids = [ ], table_alias = nil)
  return Source::Human.none if person_ids.empty?

  s  = Source::Human.arel_table
  sr = Role.arel_table

  a = s.alias("a_#{table_alias}")

  b = s.project(a[Arel.star]).from(a)
    .join(sr)
    .on(sr['role_object_id'].eq(a['id']))

  i = 0
  person_ids.each_with_index do |person_id, i|
    sr_a = sr.alias("#{table_alias}_#{i}")
    b = b.join(sr_a).on(
      sr_a['role_object_id'].eq(a['id']),
      sr_a['person_id'].eq(person_id),
      sr_a['type'].eq('SourceSource')
    )
    i += 1
  end

  b = b.group(a['id']).having(sr['role_object_id'].count.eq(person_ids.count))
  b = b.as("z_#{table_alias}")

  Source::Human.joins(Arel::Nodes::InnerJoin.new(b, Arel::Nodes::On.new(b['id'].eq(s['id']))))
end

.identical(attr) ⇒ Scope

Parameters:

  • attr (Hash)

    of matchable attributes

Returns:

  • (Scope)


39
40
41
# File 'app/models/source/human.rb', line 39

def self.identical(attr)
  Source::Human.none
end

.similar(attr) ⇒ Scope

TODO: Special case of Source::Human needs to check for roles of ‘SourceSource’ matching.

Parameters:

  • attr (Hash)

    of matchable attributes

Returns:

  • (Scope)


33
34
35
# File 'app/models/source/human.rb', line 33

def self.similar(attr)
  Source::Human.none
end

Instance Method Details

#at_least_one_person_is_providedIgnored (protected)

Returns:

  • (Ignored)


94
95
96
97
98
# File 'app/models/source/human.rb', line 94

def at_least_one_person_is_provided
  if people.size < 1 && source_source_roles.size < 1 && roles.size < 1 # size not count
    errors.add(:base, 'at least one person must be provided')
  end
end

#authority_nameString

Returns:

  • (String)


24
25
26
27
28
# File 'app/models/source/human.rb', line 24

def authority_name
  Utilities::Strings.authorship_sentence(
    people.pluck(:last_name)
  )
end

#get_cachedObject (protected)



84
85
86
# File 'app/models/source/human.rb', line 84

def get_cached
  [authority_name, year].compact.join(', ')
end

#identicalScope

Returns:

  • (Scope)


49
50
51
# File 'app/models/source/human.rb', line 49

def identical
  Source::Human.none
end

#set_cachedIgnored (protected)

Returns:

  • (Ignored)


89
90
91
# File 'app/models/source/human.rb', line 89

def set_cached
  update_column(:cached, get_cached)
end

#similarScope

Returns:

  • (Scope)


44
45
46
# File 'app/models/source/human.rb', line 44

def similar
  Source::Human.none
end

#sv_cached_namesObject (protected)

this cannot be moved to soft_validation_extensions



100
101
102
103
104
105
# File 'app/models/source/human.rb', line 100

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 != get_cached
end