Class: Puree::Extractor::ResearchOutput

Inherits:
Resource
  • Object
show all
Defined in:
lib/puree/extractor/research_output.rb

Overview

Research output extractor.

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from Puree::Extractor::Resource

Instance Method Details

#count(params = {}) ⇒ Integer

Count of records available.

Parameters:

  • params (Hash) (defaults to: {})

    Combined GET and POST parameters for all records

Returns:

  • (Integer)


21
22
23
# File 'lib/puree/extractor/research_output.rb', line 21

def count(params = {})
  record_count :research_output, params
end

#find(id) ⇒ Puree::Model::ResearchOutput?

Parameters:

  • id (String)

Returns:



11
12
13
14
15
# File 'lib/puree/extractor/research_output.rb', line 11

def find(id)
  super id: id,
        api_resource_type: :research_output,
        xml_extractor_resource_type: :research_output
end

#random(params = {}) ⇒ Puree::Model::ResearchOutput or subclass?

Random record. Includes the metadata from Puree::Model::ResearchOutput as a minimum.

Parameters:

  • params (Hash) (defaults to: {})

    Combined GET and POST parameters for all records

Returns:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/puree/extractor/research_output.rb', line 29

def random(params = {})
  client = Puree::REST::Client.new @config
  offset = rand(0..count(params)-1)
  params[:size] = 1
  params[:offset] = offset
  response = client.research_outputs.all_complex params: params
  research_outputs_hash = Puree::XMLExtractor::Collection.research_outputs response.to_s
  research_outputs_array = []
  research_outputs_hash.each do |k, v|
    research_outputs_array += v
  end
  return nil if research_outputs_array.empty?
  research_outputs_array[0]
end