Class: Puree::Dataset
Overview
Dataset resource
Instance Method Summary collapse
-
#access ⇒ String
Open access permission.
-
#associated ⇒ Hash
Combines project and publication.
-
#available ⇒ Hash
Date made available.
-
#description ⇒ String
Description.
-
#doi ⇒ String
Digital Object Identifier.
-
#file ⇒ Array<Hash>
Supporting file.
-
#geographical ⇒ Array<String>
Geographical coverage.
-
#initialize(endpoint: nil, username: nil, password: nil) ⇒ Dataset
constructor
A new instance of Dataset.
-
#keyword ⇒ Array<String>
Keyword.
-
#link ⇒ Array<Hash>
Link.
-
#metadata ⇒ Hash
All metadata.
-
#organisation ⇒ Hash
Organisation.
-
#person ⇒ Hash
Person (internal, external, other).
-
#production ⇒ Hash
Date of data production.
-
#project ⇒ Array<Hash>
Project.
-
#publication ⇒ Array<Hash>
Publication.
-
#publisher ⇒ String
Publisher.
-
#temporal ⇒ Hash
Temporal coverage.
-
#title ⇒ String
Title.
Methods inherited from Resource
#content, #created, #get, #modified, #response, #set_content, #uuid
Constructor Details
#initialize(endpoint: nil, username: nil, password: nil) ⇒ Dataset
Returns a new instance of Dataset.
10 11 12 13 14 15 |
# File 'lib/puree/dataset.rb', line 10 def initialize(endpoint: nil, username: nil, password: nil) super(api: :dataset, endpoint: endpoint, username: username, password: password) end |
Instance Method Details
#access ⇒ String
Open access permission
214 215 216 217 |
# File 'lib/puree/dataset.rb', line 214 def access data = node 'openAccessPermission' !data.nil? && !data.empty? ? data['term']['localizedString']["__content__"].strip : '' end |
#associated ⇒ Hash
Combines project and publication
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/puree/dataset.rb', line 58 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 |
#available ⇒ Hash
Date made available
178 179 180 181 |
# File 'lib/puree/dataset.rb', line 178 def available data = node('dateMadeAvailable') Puree::Date.normalise(data) end |
#description ⇒ String
Description
115 116 117 118 119 |
# File 'lib/puree/dataset.rb', line 115 def description path = '//descriptions/classificationDefinedField/value/localizedString' xpath_result = xpath_query path xpath_result ? xpath_result.text.strip : '' end |
#doi ⇒ String
Digital Object Identifier
256 257 258 259 260 |
# File 'lib/puree/dataset.rb', line 256 def doi path = '//content/doi' xpath_result = xpath_query path xpath_result ? xpath_result.text.strip : '' end |
#file ⇒ Array<Hash>
Supporting file
223 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 |
# File 'lib/puree/dataset.rb', line 223 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 |
#geographical ⇒ Array<String>
Geographical coverage
186 187 188 189 190 191 192 193 194 |
# File 'lib/puree/dataset.rb', line 186 def geographical data = node 'geographicalCoverage' if !data.nil? && !data.empty? data = data['localizedString']["__content__"] data.is_a?(Array) ? data.uniq : data.split(',').map(&:strip).uniq else [] end end |
#keyword ⇒ Array<String>
Keyword
105 106 107 108 109 110 |
# File 'lib/puree/dataset.rb', line 105 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 ⇒ Array<Hash>
Link
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/puree/dataset.rb', line 20 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 |
#metadata ⇒ Hash
All metadata
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# 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['person'] = person o['project'] = project o['production'] = production o['publication'] = publication o['publisher'] = publisher o['temporal'] = temporal o['title'] = title o end |
#organisation ⇒ Hash
Organisation
36 37 38 39 40 41 42 43 44 |
# File 'lib/puree/dataset.rb', line 36 def organisation path = '//content/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 |
#person ⇒ Hash
Person (internal, external, other)
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 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 |
# File 'lib/puree/dataset.rb', line 124 def person data = node('persons') persons = {} if !data.nil? && !data.empty? data = data['dataSetPersonAssociation'] else return persons end internal_persons = [] external_persons = [] other_persons = [] case data when Array data.each do |d| person = generic_person d if d.key? 'person' person['uuid'] = d['person']['uuid'].strip internal_persons << person end if d.key? 'externalPerson' person['uuid'] = d['externalPerson']['uuid'].strip external_persons << person end if !d.key?('person') && !d.key?('externalPerson') person['uuid'] = '' other_persons << person end end when Hash person = generic_person data if data.key? 'person' person['uuid'] = data['person']['uuid'].strip internal_persons << person end if data.key? 'externalPerson' person['uuid'] = data['externalPerson']['uuid'].strip external_persons << person end if !data.key?('person') && !data.key?('externalPerson') person['uuid'] = '' other_persons << person end end persons['internal'] = internal_persons.uniq persons['external'] = external_persons.uniq persons['other'] = other_persons.uniq persons end |
#production ⇒ Hash
Date of data production
199 200 201 |
# File 'lib/puree/dataset.rb', line 199 def production temporal_range 'dateOfDataProduction', 'endDateOfDataProduction' end |
#project ⇒ Array<Hash>
Project
75 76 77 |
# File 'lib/puree/dataset.rb', line 75 def project associated_type('Research').uniq end |
#publication ⇒ Array<Hash>
Publication
82 83 84 85 86 87 88 89 90 |
# File 'lib/puree/dataset.rb', line 82 def publication data_arr = [] associated.each do |i| if i['type'] != 'Research' data_arr << i end end data_arr.uniq end |
#publisher ⇒ String
Publisher
49 50 51 52 53 |
# File 'lib/puree/dataset.rb', line 49 def publisher path = '//publisher/name' xpath_result = xpath_query path xpath_result ? xpath_result.text.strip : '' end |
#temporal ⇒ Hash
Temporal coverage
207 208 209 |
# File 'lib/puree/dataset.rb', line 207 def temporal temporal_range 'temporalCoverageStartDate', 'temporalCoverageEndDate' end |
#title ⇒ String
Title
96 97 98 99 100 |
# File 'lib/puree/dataset.rb', line 96 def title path = '//title/localizedString' xpath_result = xpath_query path xpath_result ? xpath_result.text.strip : '' end |