Class: Source::Human
- Inherits:
-
Source
- Object
- ActiveRecord::Base
- ApplicationRecord
- Source
- Source::Human
- 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
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
Class Method Summary collapse
- .by_person(person_ids = [ ], table_alias = nil) ⇒ Object
- .identical(attr) ⇒ Scope
-
.similar(attr) ⇒ Scope
TODO: Special case of Source::Human needs to check for roles of 'SourceSource' matching.
Instance Method Summary collapse
- #at_least_one_person_is_provided ⇒ Ignored protected
- #authority_name ⇒ String
- #identical ⇒ Scope
- #set_cached ⇒ Ignored protected
- #similar ⇒ Scope
Methods inherited from Source
batch_create, batch_preview, #cited_objects, #clone, #is_bibtex?, #is_in_project?, #reject_project_sources, select_optimized, used_recently
Methods included from SoftValidation
#clear_soft_validations, #fix_soft_validations, #soft_fixed?, #soft_valid?, #soft_validate, #soft_validated?, #soft_validations
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 Shared::HasRoles
Methods included from Shared::Documentation
#document_array=, #documented?, #reject_documentation, #reject_documents
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
#identified?, #next_by_identifier, #previous_by_identifier, #reject_identifiers
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::Timestamps
#data_breakdown_for_chartkick_recent
Methods included from Housekeeping::Users
#set_created_by_id, #set_updated_by_id
Methods inherited from ApplicationRecord
Class Method Details
.by_person(person_ids = [ ], table_alias = nil) ⇒ Object
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 81 82 83 |
# File 'app/models/source/human.rb', line 56 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 |
Instance Method Details
#at_least_one_person_is_provided ⇒ Ignored (protected)
93 94 95 96 97 |
# File 'app/models/source/human.rb', line 93 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_name ⇒ String
27 28 29 30 31 |
# File 'app/models/source/human.rb', line 27 def Utilities::Strings.( people.collect { |p| p.last_name } ) end |
#identical ⇒ Scope
52 53 54 |
# File 'app/models/source/human.rb', line 52 def identical Source::Human.none end |
#set_cached ⇒ Ignored (protected)
88 89 90 |
# File 'app/models/source/human.rb', line 88 def set_cached update_column(:cached, ) end |