Class: Puree::Dataset

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

Overview

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

Returns a new instance of Dataset.

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

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

Instance Method Details

#accessString

Open access permission

Returns:

  • (String)


215
216
217
218
# File 'lib/puree/dataset.rb', line 215

def access
  path = '/openAccessPermission/term/localizedString'
  xpath_query_for_single_value path
end

#associatedArray<Hash>

Combines project and publication

Returns:

  • (Array<Hash>)


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

def associated
  path = '/associatedContent//relatedContent'
  xpath_result =  xpath_query path
  data_arr = []
  xpath_result.each { |i|
    data = {}
    data['type'] = i.xpath('typeClassification').text.strip
    data['title'] = i.xpath('title').text.strip
    data['uuid'] = i.attr('uuid').strip
    data_arr << data
  }
  data_arr.uniq
end

#availableHash

Date made available

Returns:

  • (Hash)


180
181
182
# File 'lib/puree/dataset.rb', line 180

def available
  temporal_start_date 'dateMadeAvailable'
end

#descriptionString

Description

Returns:

  • (String)


116
117
118
119
# File 'lib/puree/dataset.rb', line 116

def description
  path = '/descriptions/classificationDefinedField/value/localizedString'
  xpath_query_for_single_value path
end

#doiString

Digital Object Identifier

Returns:

  • (String)


257
258
259
260
# File 'lib/puree/dataset.rb', line 257

def doi
  path = '/doi'
  xpath_query_for_single_value path
end

#fileArray<Hash>

Supporting file

Returns:

  • (Array<Hash>)


224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'lib/puree/dataset.rb', line 224

def file
  path = '/documents/document'
  xpath_result = xpath_query path

  docs = []

  xpath_result.each do |d|
    doc = {}
    # doc['id'] = f.xpath('id').text.strip
    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
    doc['title'] = d.xpath('title').text.strip
    # doc['createdDate'] = d.xpath('createdDate').text.strip
    # doc['visibleOnPortalDate'] = d.xpath('visibleOnPortalDate').text.strip
    # doc['limitedVisibility'] = d.xpath('limitedVisibility').text.strip

    license = {}
    license_name = d.xpath('documentLicense/term/localizedString').text.strip
    license['name'] = license_name
    license_url = d.xpath('documentLicense/description/localizedString').text.strip
    license['url'] = license_url
    doc['license'] = license
    docs << doc

  end
  docs.uniq
end

#geographicalArray<String>

Geographical coverage

Returns:

  • (Array<String>)


187
188
189
190
191
192
193
194
195
# File 'lib/puree/dataset.rb', line 187

def geographical
  path = '/geographicalCoverage/localizedString'
  xpath_result = xpath_query path
  data = []
  xpath_result.each do |i|
    data << i.text.strip
  end
  data
end

#keywordArray<String>

Keyword

Returns:

  • (Array<String>)


106
107
108
109
110
111
# File 'lib/puree/dataset.rb', line 106

def keyword
  path = '/keywordGroups/keywordGroup/keyword/userDefinedKeyword/freeKeyword'
  xpath_result =  xpath_query path
  data_arr = xpath_result.map { |i| i.text.strip }
  data_arr.uniq
end

Link

Returns:

  • (Array<Hash>)


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

def link
  path = '/links/link'
  xpath_result = xpath_query path
  data = []
  xpath_result.each { |i|
    o = {}
    o['url'] = i.xpath('url').text.strip
    o['description'] = i.xpath('description').text.strip
    data << o
  }
  data.uniq
end

#metadataHash

All metadata

Returns:

  • (Hash)


271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
# File 'lib/puree/dataset.rb', line 271

def 
  o = super
  o['access'] = access
  o['associated'] = associated
  o['available'] = available
  o['description'] = description
  o['doi'] = doi
  o['file'] = file
  o['geographical'] = geographical
  o['keyword'] = keyword
  o['link'] = link
  o['organisation'] = organisation
  o['owner'] = owner
  o['person'] = person
  o['project'] = project
  o['production'] = production
  o['publication'] = publication
  o['publisher'] = publisher
  o['temporal'] = temporal
  o['title'] = title
  o
end

#organisationArray<Hash>

Organisation

Returns:

  • (Array<Hash>)


124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/puree/dataset.rb', line 124

def organisation
  path = '/organisations/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

#ownerHash

Owner

Returns:

  • (Hash)


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

def owner
  path = '/managedBy'
  xpath_result =  xpath_query path
  o = {}
  o['uuid'] = xpath_result.xpath('@uuid').text.strip
  o['name'] = xpath_result.xpath('name/localizedString').text.strip
  o['type'] = xpath_result.xpath('typeClassification/term/localizedString').text.strip
   o
end

#personArray<Hash>

Person (internal, external, other)

Returns:

  • (Array<Hash>)


141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/puree/dataset.rb', line 141

def person
  data = {}
  # internal
  path = '/persons/dataSetPersonAssociation'
  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

#productionHash

Date of data production

Returns:

  • (Hash)


200
201
202
# File 'lib/puree/dataset.rb', line 200

def production
  temporal_range 'dateOfDataProduction', 'endDateOfDataProduction'
end

#projectArray<Hash>

Project

Returns:

  • (Array<Hash>)


77
78
79
# File 'lib/puree/dataset.rb', line 77

def project
  associated_type('Research').uniq
end

#publicationArray<Hash>

Publication

Returns:

  • (Array<Hash>)


84
85
86
87
88
89
90
91
92
# File 'lib/puree/dataset.rb', line 84

def publication
  data_arr = []
  associated.each do |i|
    if i['type'] != 'Research'
      data_arr << i
    end
  end
  data_arr.uniq
end

#publisherString

Publisher

Returns:

  • (String)


52
53
54
55
# File 'lib/puree/dataset.rb', line 52

def publisher
  path = '/publisher/name'
  xpath_query_for_single_value path
end

#temporalHash

Temporal coverage

Returns:

  • (Hash)


208
209
210
# File 'lib/puree/dataset.rb', line 208

def temporal
  temporal_range 'temporalCoverageStartDate', 'temporalCoverageEndDate'
end

#titleString

Title

Returns:

  • (String)


98
99
100
101
# File 'lib/puree/dataset.rb', line 98

def title
  path = '/title/localizedString'
  xpath_query_for_single_value path
end