Class: Puree::XMLExtractor::Publication

Inherits:
Resource show all
Includes:
AssociatedMixin, ExternalOrganisationsMixin, WorkflowStateMixin
Defined in:
lib/puree/xml_extractor/publication.rb

Overview

Publication XML extractor.

Direct Known Subclasses

JournalArticle, PaperBase, Thesis

Instance Method Summary collapse

Methods included from WorkflowStateMixin

#workflow_state

Methods included from ExternalOrganisationsMixin

#external_organisations

Methods included from AssociatedMixin

#associated

Methods inherited from Resource

#created, #get_data?, #locale, #modified, #uuid, #xpath_query

Methods inherited from Base

#xpath_query_for_multi_value, #xpath_query_for_single_value

Constructor Details

#initialize(xml:) ⇒ Publication

Returns a new instance of Publication.



12
13
14
15
# File 'lib/puree/xml_extractor/publication.rb', line 12

def initialize(xml:)
  @resource_type = :publication
  super
end

Instance Method Details

#bibliographical_noteString?

Returns:

  • (String, nil)


18
19
20
# File 'lib/puree/xml_extractor/publication.rb', line 18

def bibliographical_note
  xpath_query_for_single_value('/bibliographicalNote')
end

#categoryString?

Returns:

  • (String, nil)


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

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

#descriptionString?

Returns:

  • (String, nil)


28
29
30
# File 'lib/puree/xml_extractor/publication.rb', line 28

def description
  xpath_query_for_single_value '/abstract/localizedString'
end

#doisArray<String>?

Returns:

  • (Array<String>, nil)


33
34
35
# File 'lib/puree/xml_extractor/publication.rb', line 33

def dois
  xpath_query_for_multi_value '/electronicVersionAssociations/electronicVersionDOIAssociations/electronicVersionDOIAssociation/doi'
end

#filesArray<Puree::Model::File>

Returns:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/puree/xml_extractor/publication.rb', line 38

def files
  xpath_result = xpath_query '/electronicVersionAssociations/electronicVersionFileAssociations/electronicVersionFileAssociation'
  docs = []
  xpath_result.each do |d|
    model = Puree::Model::File.new
    model.name = d.xpath('file/fileName').text.strip
    model.mime = d.xpath('file/mimeType').text.strip
    model.size = d.xpath('file/size').text.strip.to_i
    model.url = d.xpath('file/url').text.strip
    document_license = d.xpath('licenseType')
    if !document_license.empty?
      license = Puree::Model::CopyrightLicense.new
      license.name = document_license.xpath('term/localizedString').text.strip
      license.url = document_license.xpath('description/localizedString').text.strip
      model.license = license if license.data?
    end
    docs << model
  end
  docs.uniq { |d| d.url }
end

#keywordsArray<String>

Returns:

  • (Array<String>)


60
61
62
63
64
# File 'lib/puree/xml_extractor/publication.rb', line 60

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

#languageString?

Returns:

  • (String, nil)


67
68
69
# File 'lib/puree/xml_extractor/publication.rb', line 67

def language
  xpath_query_for_single_value '/language/term/localizedString'
end

Returns:

  • (Array<String>, nil)


72
73
74
# File 'lib/puree/xml_extractor/publication.rb', line 72

def links
  xpath_query_for_multi_value '/electronicVersionAssociations/electronicVersionLinkAssociations/electronicVersionLinkAssociation/link'
end

#organisationsArray<Puree::Model::OrganisationHeader>



77
78
79
80
# File 'lib/puree/xml_extractor/publication.rb', line 77

def organisations
  xpath_result = xpath_query '/organisations/association/organisation'
  Puree::XMLExtractor::Shared.organisation_multi_header xpath_result
end

#ownerPuree::Model::OrganisationHeader?



83
84
85
86
# File 'lib/puree/xml_extractor/publication.rb', line 83

def owner
  xpath_result = xpath_query '/owner'
  Puree::XMLExtractor::Shared.organisation_header xpath_result
end

#persons_externalArray<Puree::Model::EndeavourPerson>

Returns:



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

def persons_external
  persons 'external'
end

#persons_internalArray<Puree::Model::EndeavourPerson>

Returns:



89
90
91
# File 'lib/puree/xml_extractor/publication.rb', line 89

def persons_internal
  persons 'internal'
end

#persons_otherArray<Puree::Model::EndeavourPerson>

Returns:



99
100
101
# File 'lib/puree/xml_extractor/publication.rb', line 99

def persons_other
  persons 'other'
end

#publication_placeString?

Returns:

  • (String, nil)


104
105
106
107
108
109
# File 'lib/puree/xml_extractor/publication.rb', line 104

def publication_place
  # handles variations in path
  xpath_result = xpath_query_for_single_value '/associatedPublisher/placeOfPublication'
  xpath_result = xpath_query_for_single_value '/associatedPublishers/placeOfPublication' if !xpath_result
  xpath_result
end

#publisherString?

Returns:

  • (String, nil)


112
113
114
115
116
117
# File 'lib/puree/xml_extractor/publication.rb', line 112

def publisher
  # handles variations in path
  xpath_result = xpath_query_for_single_value '/associatedPublisher/publisher/name'
  xpath_result = xpath_query_for_single_value '/associatedPublishers/publisher/name' if !xpath_result
  xpath_result
end

#scopus_idString?

Returns:

  • (String, nil)


120
121
122
123
124
125
126
127
128
# File 'lib/puree/xml_extractor/publication.rb', line 120

def scopus_id
  # xpath_result = xpath_query_for_single_value '/external/secondarySource'
  xpath_result = xpath_query '/external/secondarySource'
  return if xpath_result.empty?
  source = xpath_result.xpath('@source')
  if source && source.text.strip === 'Scopus'
    return xpath_result.xpath('@source_id').text.strip
  end
end

#statusesArray<Puree::Model::PublicationStatus>



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/puree/xml_extractor/publication.rb', line 131

def statuses
  xpath_result = xpath_query '/publicationStatuses/publicationStatus'
  data = []
  xpath_result.each do |i|
    s = Puree::Model::PublicationStatus.new
    s.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

    s.date = Puree::Util::Date.hash_to_time ymd

    data << s
  end
  data.uniq { |d| d.stage }
end

#subtitleString?

Returns:

  • (String, nil)


151
152
153
# File 'lib/puree/xml_extractor/publication.rb', line 151

def subtitle
  xpath_query_for_single_value '/subtitle'
end

#titleString?

Returns:

  • (String, nil)


156
157
158
# File 'lib/puree/xml_extractor/publication.rb', line 156

def title
  xpath_query_for_single_value '/title'
end

#translated_subtitleString?

Returns:

  • (String, nil)


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

def translated_subtitle
  xpath_query_for_single_value '/translatedSubtitle/localizedString'
end

#translated_titleString?

Returns:

  • (String, nil)


166
167
168
# File 'lib/puree/xml_extractor/publication.rb', line 166

def  translated_title
  xpath_query_for_single_value '/translatedTitle/localizedString'
end

#typeString?

Returns:

  • (String, nil)


171
172
173
# File 'lib/puree/xml_extractor/publication.rb', line 171

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