Class: Person
Overview
Person - A named singular entity; A Person may have a one to one relationship with a User. A Person is a Container.
profile: Each person has a profile which is actually just a collection that is explicitly referenced by the person using a :has_profile relationship.
Constant Summary
collapse
- GRAVATAR_URL =
"//www.gravatar.com/avatar/"
Instance Attribute Summary collapse
Instance Method Summary
collapse
#add_editor_group, ids_from_tokens, #remove_editor_group
#as_json, #as_rdf_object, #to_partial_path
#human_readable_type
#noid, #to_key, #to_param
#exists?
Instance Attribute Details
#mime_type ⇒ Object
Returns the value of attribute mime_type.
19
20
21
|
# File 'app/repository_models/person.rb', line 19
def mime_type
@mime_type
end
|
Instance Method Details
#add_editor(obj) ⇒ Object
75
76
77
|
# File 'app/repository_models/person.rb', line 75
def add_editor(obj)
false
end
|
#add_profile_image(file) ⇒ Object
127
128
129
130
131
|
# File 'app/repository_models/person.rb', line 127
def add_profile_image(file)
self.content.content = file
self.mime_type = file.content_type
generate_derivatives
end
|
#add_work(work) ⇒ Object
56
57
58
59
60
61
62
63
|
# File 'app/repository_models/person.rb', line 56
def add_work(work)
return unless validate_work(work)
self.works << work
self.save!
work.editors << self
work.permissions_attributes = [{name: self.depositor, access: "edit", type: "person"}] unless work.depositor == self.depositor
work.save!
end
|
#can_be_member_of_collection?(collection) ⇒ Boolean
144
145
146
|
# File 'app/repository_models/person.rb', line 144
def can_be_member_of_collection?(collection)
false
end
|
#date_uploaded ⇒ Object
83
84
85
|
# File 'app/repository_models/person.rb', line 83
def date_uploaded
Time.new(create_date).strftime("%Y-%m-%d")
end
|
#first_name ⇒ Object
87
88
89
|
# File 'app/repository_models/person.rb', line 87
def first_name
name_parser.given
end
|
#gravatar_link ⇒ Object
133
134
135
136
137
138
|
# File 'app/repository_models/person.rb', line 133
def gravatar_link
return @gravatar_link unless @gravatar_link.blank?
@gravatar_link = File.join(GRAVATAR_URL, email_hash(self.email), "?s=300")
@gravatar_link += "&d=" + File.join(GRAVATAR_URL, email_hash(self.alternate_email), "?s=300") unless self.alternate_email.blank?
@gravatar_link
end
|
#group_names ⇒ Object
121
122
123
|
# File 'app/repository_models/person.rb', line 121
def group_names
@group_names ||= self.groups.collect{|g| g.title }
end
|
#last_name ⇒ Object
91
92
93
|
# File 'app/repository_models/person.rb', line 91
def last_name
name_parser.family
end
|
#name_parser ⇒ Object
95
96
97
|
# File 'app/repository_models/person.rb', line 95
def name_parser
Namae.parse(self.name).first
end
|
#remove_editor(obj) ⇒ Object
79
80
81
|
# File 'app/repository_models/person.rb', line 79
def remove_editor(obj)
false
end
|
#remove_work(work) ⇒ Object
65
66
67
68
69
70
71
72
73
|
# File 'app/repository_models/person.rb', line 65
def remove_work(work)
if( ( work.depositor != self.depositor ) && ( self.works.include?( work ) ) )
self.works.delete(work)
self.save!
work.editors.delete(self)
work.edit_users = work.edit_users - [self.depositor]
work.save!
end
end
|
#representative ⇒ Object
113
114
115
|
# File 'app/repository_models/person.rb', line 113
def representative
to_param
end
|
#representative_image_url ⇒ Object
140
141
142
|
# File 'app/repository_models/person.rb', line 140
def representative_image_url
self.thumbnail.content.present? ? generate_thumbnail_url : gravatar_link
end
|
#to_s ⇒ Object
117
118
119
|
# File 'app/repository_models/person.rb', line 117
def to_s
name || "No Title"
end
|
#to_solr(solr_doc = {}, opts = {}) ⇒ Object
103
104
105
106
107
108
109
110
111
|
# File 'app/repository_models/person.rb', line 103
def to_solr(solr_doc={}, opts={})
super(solr_doc, opts)
Solrizer.set_field(solr_doc, 'generic_type', 'Person', :facetable)
solr_doc['read_access_group_ssim'] = 'public'
solr_doc['has_user_bsi'] = !!User.exists?(repository_id: pid)
solr_doc[Solrizer.solr_name('representative', :stored_searchable)] = self.representative
solr_doc[Solrizer.solr_name('representative_image_url', :stored_searchable)] = self.representative_image_url
solr_doc
end
|
#user ⇒ Object
99
100
101
|
# File 'app/repository_models/person.rb', line 99
def user
persisted? ? User.where(repository_id: pid).first : nil
end
|
#validate_work(work) ⇒ Object