Class: Unstructured::Collection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/unstructured/collection.rb

Direct Known Subclasses

ChunkCollection

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#dataObject (readonly)

Returns the value of attribute data.



7
8
9
# File 'lib/unstructured/collection.rb', line 7

def data
  @data
end

#totalObject (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

.typeObject

Raises:

  • (NotImplementedError)


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_hObject



23
24
25
# File 'lib/unstructured/collection.rb', line 23

def to_h
  @raw_data
end