Class: SmartRecruiters::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/smartrecruiters/collection.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content:, limit:, offset:, next_page_id:, total_found:) ⇒ Collection

Returns a new instance of Collection.



26
27
28
29
30
31
32
# File 'lib/smartrecruiters/collection.rb', line 26

def initialize(content:, limit:, offset:, next_page_id:, total_found:)
  @content = content
  @limit = limit
  @offset = offset
  @next_page_id = next_page_id
  @total_found = total_found
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



5
6
7
# File 'lib/smartrecruiters/collection.rb', line 5

def content
  @content
end

#limitObject (readonly)

Returns the value of attribute limit.



5
6
7
# File 'lib/smartrecruiters/collection.rb', line 5

def limit
  @limit
end

#next_page_idObject (readonly)

Returns the value of attribute next_page_id.



5
6
7
# File 'lib/smartrecruiters/collection.rb', line 5

def next_page_id
  @next_page_id
end

#offsetObject (readonly)

Returns the value of attribute offset.



5
6
7
# File 'lib/smartrecruiters/collection.rb', line 5

def offset
  @offset
end

#total_foundObject (readonly)

Returns the value of attribute total_found.



5
6
7
# File 'lib/smartrecruiters/collection.rb', line 5

def total_found
  @total_found
end

Class Method Details

.from_response(response, type:) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/smartrecruiters/collection.rb', line 7

def self.from_response(response, type:)
  body = response.body

  if body.is_a?(Array)
    new(
      content: body.map { |attrs| type.new(attrs) },
      limit: nil, offset: nil, next_page_id: nil, total_found: nil
    )
  else
    new(
      content: body['content'].map { |attrs| type.new(attrs) },
      limit: body['limit'],
      offset: body['offset'],
      next_page_id: body['nextPageId'],
      total_found: body['totalFound']
    )
  end
end