Class: Datarobot::AiApi::Page

Inherits:
Delegator
  • Object
show all
Defined in:
lib/datarobot/ai_api/page.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, param_collection) ⇒ Page

Creates a paginated collectoin of objects of type klass. Uses a parsed response body of paginated data to initialize group of objects



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/datarobot/ai_api/page.rb', line 8

def initialize(klass, param_collection)
  @items = param_collection["data"].map do |params|
    klass.new(params)
  end
  @klass = klass
  @total = param_collection["total"]
  if param_collection["links"] # predictions don't have pages
    @links = param_collection["links"]
    @next_page = param_collection["links"]["next"]
    @previous_page = param_collection["links"]["previous"]
  end
end

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items.



4
5
6
# File 'lib/datarobot/ai_api/page.rb', line 4

def items
  @items
end

#klassObject (readonly)

Returns the value of attribute klass.



4
5
6
# File 'lib/datarobot/ai_api/page.rb', line 4

def klass
  @klass
end

Returns the value of attribute links.



4
5
6
# File 'lib/datarobot/ai_api/page.rb', line 4

def links
  @links
end

#totalObject (readonly)

Returns the value of attribute total.



4
5
6
# File 'lib/datarobot/ai_api/page.rb', line 4

def total
  @total
end

Instance Method Details

#__getobj__Object

Allows all Array-like methods to be called on this class. They will be delegated to @items



45
46
47
# File 'lib/datarobot/ai_api/page.rb', line 45

def __getobj__
  @items
end

#next_pageDatarobot::AiApi::Page[klass]

Goes to the next page in the dataset if there is one. Otherwise, returns the current page



24
25
26
27
28
29
30
# File 'lib/datarobot/ai_api/page.rb', line 24

def next_page
  return self if @next_page.nil?

  Datarobot::AiApi.get(@next_page) do |data|
    self.class.new(@klass, data)
  end
end

#previous_pageDatarobot::AiApi::Page[klass]

Goes to the prevoius page in the dataset if there is one. Otherwise, returns the current page



35
36
37
38
39
40
41
# File 'lib/datarobot/ai_api/page.rb', line 35

def previous_page
  return self if @previous_page.nil?

  Datarobot::AiApi.get(@previous_page) do |data|
    self.class.new(@klass, data)
  end
end