class Datarobot::AiApi::Page

Attributes

items[R]
klass[R]
total[R]

Public Class Methods

new(klass, param_collection) click to toggle source

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

# 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

Public Instance Methods

__getobj__() click to toggle source

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

# File lib/datarobot/ai_api/page.rb, line 45
def __getobj__
  @items
end
next_page() click to toggle source

Goes to the next page in the dataset if there is one. Otherwise, returns the current page @return [Datarobot::AiApi::Page]

# 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_page() click to toggle source

Goes to the prevoius page in the dataset if there is one. Otherwise, returns the current page @return [Datarobot::AiApi::Page]

# 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