Module: Puree::XMLExtractor::Collection
- Defined in:
- lib/puree/xml_extractor/collection.rb
Overview
Resource collection XML extractor.
Class Method Summary collapse
-
.count(xml) ⇒ Object
Records available for a resource.
-
.datasets(xml) ⇒ Array<Puree::Model::Dataset>
Get models from any multi-record dataset XML response.
-
.events(xml) ⇒ Array<Puree::Model::Event>
Get models from any multi-record event XML response.
-
.external_organisations(xml) ⇒ Array<Puree::Model::ExternalOrganisation>
Get models from any multi-record external organisation XML response.
-
.journals(xml) ⇒ Array<Puree::Model::Journal>
Get models from any multi-record journal XML response.
-
.organisational_units(xml) ⇒ Array<Puree::Model::OrganisationalUnit>
Get models from any multi-record organisation XML response.
-
.persons(xml) ⇒ Array<Puree::Model::Person>
Get models from any multi-record person XML response.
-
.projects(xml) ⇒ Array<Puree::Model::Project>
Get models from any multi-record project XML response.
-
.publishers(xml) ⇒ Array<Puree::Model::Publisher>
Get models from any multi-record person XML response.
-
.research_outputs(xml) ⇒ Hash{Symbol => Array<Puree::Model::ResearchOutput class/subclass>}
Get models from any multi-record Research output XML response.
Class Method Details
.count(xml) ⇒ Object
Records available for a resource
116 117 118 119 120 |
# File 'lib/puree/xml_extractor/collection.rb', line 116 def self.count(xml) doc = Nokogiri::XML xml doc.remove_namespaces! doc.xpath('/result/count').text.to_i end |
.datasets(xml) ⇒ Array<Puree::Model::Dataset>
Get models from any multi-record dataset XML response
13 14 15 |
# File 'lib/puree/xml_extractor/collection.rb', line 13 def self.datasets(xml) models :dataset, xml, '/dataSet' end |
.events(xml) ⇒ Array<Puree::Model::Event>
Get models from any multi-record event XML response
21 22 23 |
# File 'lib/puree/xml_extractor/collection.rb', line 21 def self.events(xml) models :event, xml, '/event' end |
.external_organisations(xml) ⇒ Array<Puree::Model::ExternalOrganisation>
Get models from any multi-record external organisation XML response
29 30 31 |
# File 'lib/puree/xml_extractor/collection.rb', line 29 def self.external_organisations(xml) models :external_organisation, xml, '/externalOrganisation' end |
.journals(xml) ⇒ Array<Puree::Model::Journal>
Get models from any multi-record journal XML response
37 38 39 |
# File 'lib/puree/xml_extractor/collection.rb', line 37 def self.journals(xml) models :journal, xml, '/journal' end |
.organisational_units(xml) ⇒ Array<Puree::Model::OrganisationalUnit>
Get models from any multi-record organisation XML response
45 46 47 |
# File 'lib/puree/xml_extractor/collection.rb', line 45 def self.organisational_units(xml) models :organisational_unit, xml, '/organisationalUnit' end |
.persons(xml) ⇒ Array<Puree::Model::Person>
Get models from any multi-record person XML response
61 62 63 |
# File 'lib/puree/xml_extractor/collection.rb', line 61 def self.persons(xml) models :person, xml, '/person' end |
.projects(xml) ⇒ Array<Puree::Model::Project>
Get models from any multi-record project XML response
53 54 55 |
# File 'lib/puree/xml_extractor/collection.rb', line 53 def self.projects(xml) models :project, xml, '/project' end |
.publishers(xml) ⇒ Array<Puree::Model::Publisher>
Get models from any multi-record person XML response
69 70 71 |
# File 'lib/puree/xml_extractor/collection.rb', line 69 def self.publishers(xml) models :publisher, xml, '/publisher' end |
.research_outputs(xml) ⇒ Hash{Symbol => Array<Puree::Model::ResearchOutput class/subclass>}
Get models from any multi-record Research output XML response
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/puree/xml_extractor/collection.rb', line 77 def self.research_outputs(xml) path_from_root = File.join 'result/items', '/*' doc = Nokogiri::XML xml doc.remove_namespaces! xpath_result = doc.xpath path_from_root data = { journal_articles: [], conference_papers: [], theses: [], other: [] } xpath_result.each do |research_output| xpath_result_type = research_output.xpath('type/term/text') type = xpath_result_type.first.text.strip unless xpath_result_type.empty? if type case type when 'Journal article' extractor = Puree::XMLExtractor::JournalArticle.new research_output.to_s data[:journal_articles] << extractor.model when 'Conference paper' extractor = Puree::XMLExtractor::ConferencePaper.new research_output.to_s data[:conference_papers] << extractor.model when 'Doctoral Thesis' extractor = Puree::XMLExtractor::Thesis.new research_output.to_s data[:theses] << extractor.model when "Master's Thesis" extractor = Puree::XMLExtractor::Thesis.new research_output.to_s data[:theses] << extractor.model else extractor = Puree::XMLExtractor::ResearchOutput.new research_output.to_s data[:other] << extractor.model end end end data end |