Class: Puree::Publication

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

Overview

Publication 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) ⇒ Publication

Returns a new instance of Publication.

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/publication.rb', line 11

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

Instance Method Details

#categoryString

Category

Returns:

  • (String)


22
23
24
25
# File 'lib/puree/publication.rb', line 22

def category
  path = '/publicationCategory/publicationCategory/term/localizedString'
  xpath_query_for_single_value path
end

#descriptionString

Description

Returns:

  • (String)


30
31
32
33
# File 'lib/puree/publication.rb', line 30

def description
  path = '/abstract/localizedString'
  xpath_query_for_single_value path
end

#doiString

Digital Object Identifier

Returns:

  • (String)


50
51
52
53
# File 'lib/puree/publication.rb', line 50

def doi
  path = '//doi'
  xpath_query_for_single_value path
end

#eventHash

Event

Returns:

  • (Hash)


38
39
40
41
42
43
44
45
# File 'lib/puree/publication.rb', line 38

def event
  path = '/event'
  xpath_result = xpath_query path
  o = {}
  o['uuid'] = xpath_result.xpath('@uuid').text.strip
  o['title'] = xpath_result.xpath('title/localizedString').text.strip
  o
end

#fileArray<Hash>

Supporting file

Returns:

  • (Array<Hash>)


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/puree/publication.rb', line 58

def file
  path = '/electronicVersionAssociations/electronicVersionFileAssociations/electronicVersionFileAssociation/file'
  xpath_result = xpath_query path
  docs = []
  xpath_result.each do |d|
    doc = {}
    # doc['id'] = d.xpath('id').text
    doc['name'] = d.xpath('fileName').text.strip
    doc['mime'] = d.xpath('mimeType').text.strip
    doc['size'] = d.xpath('size').text.strip
    doc['url'] = d.xpath('url').text.strip
    docs << doc
  end
  docs.uniq
end

#metadataHash

All metadata

Returns:

  • (Hash)


185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/puree/publication.rb', line 185

def 
  o = super
  o['category'] = category
  o['description'] = description
  o['doi'] = doi
  o['event'] = event
  o['file'] = file
  o['organisation'] = organisation
  o['page'] = page
  o['person'] = person
  o['status'] = status
  o['subtitle'] = subtitle
  o['title'] = title
  o['type'] = type
  o
end

#organisationArray<Hash>

Organisation

Returns:

  • (Array<Hash>)


77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/puree/publication.rb', line 77

def organisation
  path = '/organisations/association/organisation'
  xpath_result = xpath_query path
  data = []
  xpath_result.each do |i|
    o = {}
    o['uuid'] = i.xpath('@uuid').text.strip
    o['name'] = i.xpath('name/localizedString').text.strip
    o['type'] = i.xpath('typeClassification/term/localizedString').text.strip
    data << o
  end
  data
end

#pageArray<String>

Page

Returns:

  • (Array<String>)


94
95
96
97
# File 'lib/puree/publication.rb', line 94

def page
  path = '/numberOfPages'
  xpath_query_for_single_value path
end

#personArray<Hash>

Person (internal, external, other)

Returns:

  • (Array<Hash>)


102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/puree/publication.rb', line 102

def person
  data = {}
  # internal
  path = '/persons/personAssociation'
  xpath_result = xpath_query path
  internal = []
  external = []
  other = []

  xpath_result.each do |i|
    o = {}
    name = {}
    name['first'] = i.xpath('name/firstName').text.strip
    name['last'] = i.xpath('name/lastName').text.strip
    o['name'] = name
    o['role'] = i.xpath('personRole/term/localizedString').text.strip

    uuid_internal = i.at_xpath('person/@uuid')
    uuid_external = i.at_xpath('externalPerson/@uuid')
    if uuid_internal
      o['uuid'] = uuid_internal
      internal << o
    elsif uuid_external
      o['uuid'] = uuid_external
      external << o
    else
      other << o
      o['uuid'] = ''
    end
  end
  data['internal'] = internal
  data['external'] = external
  data['other'] = other
  data
end

#statusArray<Hash>

Status

Returns:

  • (Array<Hash>)


141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/puree/publication.rb', line 141

def status
  path = '/publicationStatuses/publicationStatus'
  xpath_result = xpath_query path
  data = []
  xpath_result.each do |i|
    o = {}
    o['stage'] = i.xpath('publicationStatus/term/localizedString').text.strip
    ymd = {}
    ymd['year'] = i.xpath('publicationDate/year').text.strip
    ymd['month'] = i.xpath('publicationDate/month').text.strip
    ymd['day'] = i.xpath('publicationDate/day').text.strip
    o['date'] = Puree::Date.normalise(ymd)
    data << o
  end
  data
end

#subtitleString

Subtitle

Returns:

  • (String)


169
170
171
172
# File 'lib/puree/publication.rb', line 169

def subtitle
  path = '/subtitle'
  xpath_query_for_single_value path
end

#titleString

Title

Returns:

  • (String)


161
162
163
164
# File 'lib/puree/publication.rb', line 161

def title
  path = '/title'
  xpath_query_for_single_value path
end

#typeString

Type

Returns:

  • (String)


177
178
179
180
# File 'lib/puree/publication.rb', line 177

def type
  path = '/typeClassification/term/localizedString'
  xpath_query_for_single_value path
end