Class: MaisPersonClient::Person
- Inherits:
-
Object
- Object
- MaisPersonClient::Person
show all
- Defined in:
- lib/mais_person_client/person.rb
Overview
Model for a Person from the MAIS Person API
Defined Under Namespace
Classes: Address, AffData, Affiliation, Department, Email, Identifier, Location, PersonName, Place, Telephone, Url
Constant Summary
collapse
- HOME_ADDRESS_TYPES =
%w[home permanent].freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(xml) ⇒ Person
Returns a new instance of Person.
26
27
28
29
|
# File 'lib/mais_person_client/person.rb', line 26
def initialize(xml)
@xml = Nokogiri::XML(xml)
@xml.remove_namespaces!
end
|
Instance Attribute Details
#xml ⇒ Object
Returns the value of attribute xml.
24
25
26
|
# File 'lib/mais_person_client/person.rb', line 24
def xml
@xml
end
|
Instance Method Details
#academic_council? ⇒ Boolean
indicates if a person is a member of the academic council
188
189
190
191
192
193
194
195
196
197
|
# File 'lib/mais_person_client/person.rb', line 188
def academic_council?
return false if affiliations.empty?
affiliations.any? do |affiliation|
affiliation.affdata.any? do |affdata|
affdata.type == 'academic_council' && affdata.value&.downcase == 'member of academic council'
end
end
end
|
#affiliations ⇒ Object
Affiliations (multiple possible)
158
159
160
|
# File 'lib/mais_person_client/person.rb', line 158
def affiliations
xml.xpath('//affiliation').map { |aff_node| build_affiliation(aff_node) }
end
|
#card ⇒ Object
32
33
34
|
# File 'lib/mais_person_client/person.rb', line 32
def card
xml.root['card']
end
|
#directory_id ⇒ Object
241
242
243
|
# File 'lib/mais_person_client/person.rb', line 241
def directory_id
identifier_by_type('directory')
end
|
#display_name ⇒ Object
81
82
83
|
# File 'lib/mais_person_client/person.rb', line 81
def display_name
names.find { |name| name.type == 'display' }
end
|
#eduperson_affiliations ⇒ Object
225
226
227
|
# File 'lib/mais_person_client/person.rb', line 225
def eduperson_affiliations
xml.xpath('//edupersonaffiliation').map(&:text)
end
|
#eduperson_primary_affiliation ⇒ Object
221
222
223
|
# File 'lib/mais_person_client/person.rb', line 221
def eduperson_primary_affiliation
xml.at_xpath('//edupersonprimaryaffiliation')&.text
end
|
#emails ⇒ Object
Emails (multiple possible)
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/mais_person_client/person.rb', line 114
def emails
xml.xpath('//email').map do |email_node|
Email.new(
email_node['type'],
email_node['visibility'],
email_node.children.first&.text&.strip,
email_node.at_xpath('user')&.text,
email_node.at_xpath('host')&.text
)
end
end
|
#first_name ⇒ Object
86
87
88
|
# File 'lib/mais_person_client/person.rb', line 86
def first_name
registered_name&.first_name
end
|
#homepage ⇒ Object
141
142
143
|
# File 'lib/mais_person_client/person.rb', line 141
def homepage
urls.find { |url| url.type == 'homepage' }&.url
end
|
#identifier_by_type(type) ⇒ Object
211
212
213
|
# File 'lib/mais_person_client/person.rb', line 211
def identifier_by_type(type)
identifiers.find { |id| id.type == type }&.value
end
|
#identifiers ⇒ Object
200
201
202
203
204
205
206
207
208
209
|
# File 'lib/mais_person_client/person.rb', line 200
def identifiers
xml.xpath('//identifier').map do |id_node|
Identifier.new(
id_node['type'],
id_node['visibility'],
id_node['nval'],
id_node.text
)
end
end
|
#job_title ⇒ Object
109
110
111
|
# File 'lib/mais_person_client/person.rb', line 109
def job_title
titles.find { |title| title[:type] == 'job' }&.[](:title)
end
|
#last_name ⇒ Object
94
95
96
|
# File 'lib/mais_person_client/person.rb', line 94
def last_name
registered_name&.last
end
|
#listing ⇒ Object
36
37
38
|
# File 'lib/mais_person_client/person.rb', line 36
def listing
xml.root['listing']
end
|
#locations ⇒ Object
Locations (multiple possible)
146
147
148
149
150
151
152
153
154
155
|
# File 'lib/mais_person_client/person.rb', line 146
def locations
xml.xpath('//location').map do |loc_node|
Location.new(
loc_node['code'],
loc_node['type'],
loc_node['visibility'],
loc_node.text
)
end
end
|
#middle_name ⇒ Object
90
91
92
|
# File 'lib/mais_person_client/person.rb', line 90
def middle_name
registered_name&.middle
end
|
#mobile_phone ⇒ Object
233
234
235
|
# File 'lib/mais_person_client/person.rb', line 233
def mobile_phone
telephones.find { |tel| tel.type == 'mobile' }
end
|
#name_attr ⇒ Object
40
41
42
|
# File 'lib/mais_person_client/person.rb', line 40
def name_attr
xml.root['name']
end
|
#names ⇒ Object
Names (multiple possible)
73
74
75
|
# File 'lib/mais_person_client/person.rb', line 73
def names
xml.xpath('//name').map { |name_node| build_person_name(name_node) }
end
|
#orcid ⇒ Object
237
238
239
|
# File 'lib/mais_person_client/person.rb', line 237
def orcid
identifier_by_type('orcid')
end
|
#primary_effective_date ⇒ Object
returns the effective_date for the primary affiliation (affnum == '1')
178
179
180
181
182
183
184
185
|
# File 'lib/mais_person_client/person.rb', line 178
def primary_effective_date
aff = affiliations.find { |a| a.affnum == '1' }
return nil unless aff
aff.effective
end
|
#primary_email ⇒ Object
126
127
128
|
# File 'lib/mais_person_client/person.rb', line 126
def primary_email
emails.find { |email| email.type == 'primary' }&.full_email
end
|
#primary_org_code ⇒ Object
returns the org_id for the primary affiliation (affnum == '1')
168
169
170
171
172
173
174
175
|
# File 'lib/mais_person_client/person.rb', line 168
def primary_org_code
aff = affiliations.find { |a| a.affnum == '1' }
return nil unless aff
aff.department&.adminid
end
|
#primary_role ⇒ Object
returns the primary role/type for the person (from affiliation with affnum 1)
163
164
165
|
# File 'lib/mais_person_client/person.rb', line 163
def primary_role
affiliations.find { |aff| aff.affnum == '1' }&.type
end
|
#privgroups ⇒ Object
216
217
218
|
# File 'lib/mais_person_client/person.rb', line 216
def privgroups
xml.xpath('//privgroup').map(&:text)
end
|
#regid ⇒ Object
44
45
46
|
# File 'lib/mais_person_client/person.rb', line 44
def regid
xml.root['regid']
end
|
#registered_name ⇒ Object
77
78
79
|
# File 'lib/mais_person_client/person.rb', line 77
def registered_name
names.find { |name| name.type == 'registered' }
end
|
#relationship ⇒ Object
48
49
50
|
# File 'lib/mais_person_client/person.rb', line 48
def relationship
xml.root['relationship']
end
|
#source ⇒ Object
52
53
54
|
# File 'lib/mais_person_client/person.rb', line 52
def source
xml.root['source']
end
|
#stanford_end_date ⇒ Object
64
65
66
67
68
69
70
|
# File 'lib/mais_person_client/person.rb', line 64
def stanford_end_date
value = xml.root['stanfordenddate']
return nil unless value
stripped = value.strip
stripped.empty? ? nil : stripped
end
|
#sunetid ⇒ Object
56
57
58
|
# File 'lib/mais_person_client/person.rb', line 56
def sunetid
xml.root['sunetid']
end
|
#titles ⇒ Object
Titles (multiple possible)
99
100
101
102
103
104
105
106
107
|
# File 'lib/mais_person_client/person.rb', line 99
def titles
xml.xpath('//title').map do |title_node|
{
type: title_node['type'],
visibility: title_node['visibility'],
title: title_node.text
}
end
end
|
#univid ⇒ Object
60
61
62
|
# File 'lib/mais_person_client/person.rb', line 60
def univid
xml.root['univid']
end
|
#urls ⇒ Object
131
132
133
134
135
136
137
138
139
|
# File 'lib/mais_person_client/person.rb', line 131
def urls
xml.xpath('//url').map do |url_node|
Url.new(
url_node['type'],
url_node['visibility'],
url_node.text
)
end
end
|
#work_phone ⇒ Object
229
230
231
|
# File 'lib/mais_person_client/person.rb', line 229
def work_phone
telephones.find { |tel| tel.type == 'work' }
end
|