Class: Unstructured::Collection
- Inherits:
-
Object
- Object
- Unstructured::Collection
- Includes:
- Enumerable
- Defined in:
- lib/unstructured/collection.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Class Method Summary collapse
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(data:, raw_data:, total:) ⇒ Collection
constructor
A new instance of Collection.
- #to_h ⇒ Object
Constructor Details
#initialize(data:, raw_data:, total:) ⇒ Collection
Returns a new instance of Collection.
17 18 19 20 21 |
# File 'lib/unstructured/collection.rb', line 17 def initialize(data:, raw_data:, total:) @data = data @raw_data = raw_data @total = total end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
7 8 9 |
# File 'lib/unstructured/collection.rb', line 7 def data @data end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
7 8 9 |
# File 'lib/unstructured/collection.rb', line 7 def total @total end |
Class Method Details
.from_response(response) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/unstructured/collection.rb', line 9 def self.from_response(response) new( data: response.map { |attrs| type.new(attrs) }, raw_data: response, total: response.length ) end |
.type ⇒ Object
33 34 35 |
# File 'lib/unstructured/collection.rb', line 33 def self.type raise NotImplementedError end |
Instance Method Details
#each(&block) ⇒ Object
27 28 29 30 31 |
# File 'lib/unstructured/collection.rb', line 27 def each(&block) return to_enum(__method__) { @data.size } unless block_given? @data.each(&block) end |
#to_h ⇒ Object
23 24 25 |
# File 'lib/unstructured/collection.rb', line 23 def to_h @raw_data end |