Class: Puree::Extractor::Collection
- Inherits:
-
Object
- Object
- Puree::Extractor::Collection
- Includes:
- API::Authentication
- Defined in:
- lib/puree/extractor/collection.rb
Overview
A collection extractor can retrieve any number of resources of the same type.
Instance Method Summary collapse
-
#count ⇒ Fixnum
Count of records available for a resource type.
-
#get(limit: 0, offset: 0, created_start: nil, created_end: nil, modified_start: nil, modified_end: nil) ⇒ Array<Puree::Model::Resource subclass>
(also: #find)
Gets an array of objects of resource type specified in constructor.
-
#initialize(config:, resource:) ⇒ Collection
constructor
A new instance of Collection.
-
#random_resource ⇒ Puree::Model::Resource subclass?
Gets a random resource of type specified in constructor.
Constructor Details
Instance Method Details
#count ⇒ Fixnum
Count of records available for a resource type.
62 63 64 |
# File 'lib/puree/extractor/collection.rb', line 62 def count get_count end |
#get(limit: 0, offset: 0, created_start: nil, created_end: nil, modified_start: nil, modified_end: nil) ⇒ Array<Puree::Model::Resource subclass> Also known as: find
Gets an array of objects of resource type specified in constructor.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/puree/extractor/collection.rb', line 27 def get( limit: 0, offset: 0, created_start: nil, created_end: nil, modified_start: nil, modified_end: nil ) @response = @request.get rendering: :system, limit: limit, offset: offset, resource_type: @resource_type, created_start: created_start, created_end: created_end, modified_start: modified_start, modified_end: modified_end set_content @response.body end |
#random_resource ⇒ Puree::Model::Resource subclass?
Gets a random resource of type specified in constructor.
49 50 51 52 53 54 55 56 |
# File 'lib/puree/extractor/collection.rb', line 49 def random_resource @response = @request.get rendering: :system, limit: 1, offset: rand(0..count-1), resource_type: @resource_type content = set_content @response.body content[0] if content end |