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

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

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

Class Method Details

+ (Object) by_person(person_ids = [ ], table_alias = nil)



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

+ (Scope) identical(attr)

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

+ (Scope) similar(attr)

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

- (Ignored) at_least_one_person_is_provided (protected)

Returns:

  • (Ignored)


91
92
93
94
95
# File 'app/models/source/human.rb', line 91

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

- (String) authority_name

Returns:

  • (String)


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

def authority_name
  Utilities::Strings.authorship_sentence(
    people.collect { |p| p.last_name }
  )
end

- (Scope) identical

Returns:

  • (Scope)


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

def identical
  Source::Human.none
end

- (Ignored) set_cached (protected)

Returns:

  • (Ignored)


86
87
88
# File 'app/models/source/human.rb', line 86

def set_cached
  update_column(:cached, authority_name)
end

- (Scope) similar

Returns:

  • (Scope)


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

def similar
  Source::Human.none
end