Class: Puree::Person

Inherits:
Resource show all
Defined in:
lib/puree/person.rb

Overview

Person resource

Instance Attribute Summary

Attributes inherited from Resource

#response

Instance Method Summary collapse

Methods inherited from Resource

#content, #created, #get, #modified, #set_content, #uuid

Constructor Details

#initialize(endpoint: nil, username: nil, password: nil, basic_auth: nil) ⇒ Person

Returns a new instance of Person.

Parameters:

  • endpoint (String) (defaults to: nil)
  • optional

    username [String]

  • optional

    password [String]

  • optional

    basic_auth [Boolean]



11
12
13
14
15
16
17
# File 'lib/puree/person.rb', line 11

def initialize(endpoint: nil, username: nil, password: nil, basic_auth: nil)
  super(api: :person,
        endpoint: endpoint,
        username: username,
        password: password,
        basic_auth: basic_auth)
end

Instance Method Details

#affiliationArray<Hash>

Affiliation

Returns:

  • (Array<Hash>)


24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/puree/person.rb', line 24

def affiliation
  path = '//organisation'
  xpath_result =  xpath_query path
  data_arr = []
  xpath_result.each { |i|
    data = {}
    data['uuid'] = i.attr('uuid').strip
    data['name'] = i.xpath('name/localizedString').text.strip
    data_arr << data
  }
  data_arr.uniq
end

#emailArray

Email

Returns:

  • (Array)


40
41
42
43
44
45
46
# File 'lib/puree/person.rb', line 40

def email
  path = '//emails/classificationDefinedStringFieldExtension/value'
  xpath_result =  xpath_query path
  data = []
  xpath_result.each { |i| data << i.text }
  data.uniq
end

#imageArray<String>

Image URL

Returns:

  • (Array<String>)


51
52
53
54
55
56
57
# File 'lib/puree/person.rb', line 51

def image
  path = '/photos/file/url'
  xpath_result =  xpath_query path
  data = []
  xpath_result.each { |i| data << i.text }
  data.uniq
end

#keywordArray<String>

Keyword

Returns:

  • (Array<String>)


62
63
64
65
66
67
68
# File 'lib/puree/person.rb', line 62

def keyword
  path = '//keywordGroup/keyword/userDefinedKeyword/freeKeyword'
  xpath_result =  xpath_query path
  data = []
  xpath_result.each { |i| data << i.text }
  data.uniq
end

#metadataHash

All metadata

Returns:

  • (Hash)


95
96
97
98
99
100
101
102
103
104
# File 'lib/puree/person.rb', line 95

def 
  o = super
  o['affiliation'] = affiliation
  o['email'] = email
  o['image'] = image
  o['keyword'] = keyword
  o['name'] = name
  o['orcid'] = orcid
  o
end

#nameHash

Name

Returns:

  • (Hash)


73
74
75
76
77
78
79
80
81
82
# File 'lib/puree/person.rb', line 73

def name
  path = '/name'
  xpath_result =  xpath_query path
  first = xpath_result.xpath('firstName').text.strip
  last = xpath_result.xpath('lastName').text.strip
  o = {}
  o['first'] = first
  o['last'] = last
  o
end

#orcidString

ORCID

Returns:

  • (String)


87
88
89
90
# File 'lib/puree/person.rb', line 87

def orcid
  path = '/orcid'
  xpath_query_for_single_value path
end