Class: Datarobot::AiApi::Page
- Inherits:
-
Delegator
- Object
- Delegator
- Datarobot::AiApi::Page
- Defined in:
- lib/datarobot/ai_api/page.rb
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#links ⇒ Object
readonly
Returns the value of attribute links.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
-
#__getobj__ ⇒ Object
Allows all Array-like methods to be called on this class.
-
#initialize(klass, param_collection) ⇒ Page
constructor
Creates a paginated collectoin of objects of type klass.
-
#next_page ⇒ Datarobot::AiApi::Page[klass]
Goes to the next page in the dataset if there is one.
-
#previous_page ⇒ Datarobot::AiApi::Page[klass]
Goes to the prevoius page in the dataset if there is one.
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
#items ⇒ Object (readonly)
Returns the value of attribute items.
4 5 6 |
# File 'lib/datarobot/ai_api/page.rb', line 4 def items @items end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
4 5 6 |
# File 'lib/datarobot/ai_api/page.rb', line 4 def klass @klass end |
#links ⇒ Object (readonly)
Returns the value of attribute links.
4 5 6 |
# File 'lib/datarobot/ai_api/page.rb', line 4 def links @links end |
#total ⇒ Object (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_page ⇒ Datarobot::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_page ⇒ Datarobot::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 |