Class: Puree::XMLExtractor::Publication

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

Overview

Publication XMLextractor.

Instance Method Summary collapse

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.



9
10
11
12
# File 'lib/puree/xml_extractor/publication.rb', line 9

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

Instance Method Details

#categoryString?

Returns:

  • (String, nil)


15
16
17
# File 'lib/puree/xml_extractor/publication.rb', line 15

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

#descriptionString?

Returns:

  • (String, nil)


20
21
22
# File 'lib/puree/xml_extractor/publication.rb', line 20

def description
  xpath_query_for_single_value '/abstract/localizedString'
end

#doiString?

Returns:

  • (String, nil)


25
26
27
# File 'lib/puree/xml_extractor/publication.rb', line 25

def doi
  xpath_query_for_single_value '//doi'
end

#eventPuree::Model::EventHeader?

Returns:



30
31
32
33
34
35
36
37
38
39
# File 'lib/puree/xml_extractor/publication.rb', line 30

def event
  xpath_result = xpath_query '/event'
  if !xpath_result.empty?
    header = Puree::Model::EventHeader.new
    header.uuid = xpath_result.xpath('@uuid').text.strip
    header.title = xpath_result.xpath('title/localizedString').text.strip
    return header if header.data?
  end
  nil
end

#filesArray<Puree::Model::File>

Returns:



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/puree/xml_extractor/publication.rb', line 42

def files
  xpath_result = xpath_query '/electronicVersionAssociations/electronicVersionFileAssociations/electronicVersionFileAssociation/file'
  docs = []
  xpath_result.each do |d|
    model = Puree::Model::File.new
    model.name = d.xpath('fileName').text.strip
    model.mime = d.xpath('mimeType').text.strip
    model.size = d.xpath('size').text.strip.to_i
    model.url = d.xpath('url').text.strip
    docs << model
  end
  docs.uniq { |d| d.url }
end

#organisationsArray<Puree::Model::OrganisationHeader>



57
58
59
60
# File 'lib/puree/xml_extractor/publication.rb', line 57

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

#pagesFixnum?

Returns:

  • (Fixnum, nil)


63
64
65
# File 'lib/puree/xml_extractor/publication.rb', line 63

def pages
  xpath_query_for_single_value('/numberOfPages').to_i
end

#persons_externalArray<Puree::Model::EndeavourPerson>

Returns:



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

def persons_external
  persons 'external'
end

#persons_internalArray<Puree::Model::EndeavourPerson>

Returns:



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

def persons_internal
  persons 'internal'
end

#persons_otherArray<Puree::Model::EndeavourPerson>

Returns:



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

def persons_other
  persons 'other'
end

#statusesArray<Puree::Model::PublicationStatus>



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/puree/xml_extractor/publication.rb', line 83

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)


103
104
105
# File 'lib/puree/xml_extractor/publication.rb', line 103

def subtitle
  xpath_query_for_single_value '/subtitle'
end

#titleString?

Returns:

  • (String, nil)


108
109
110
# File 'lib/puree/xml_extractor/publication.rb', line 108

def title
  xpath_query_for_single_value '/title'
end

#typeString?

Returns:

  • (String, nil)


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

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