Class: Source::Human

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

Class Method Summary collapse

Instance Method Summary collapse

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